(self, args: list[str], opts: Namespace)
| 65 | """ |
| 66 | |
| 67 | def run(self, args: list[str], opts: Namespace) -> None: |
| 68 | url = args[0] if args else None |
| 69 | if url: |
| 70 | # first argument may be a local file |
| 71 | url = guess_scheme(url) |
| 72 | |
| 73 | assert self.crawler_process |
| 74 | spider_loader = self.crawler_process.spider_loader |
| 75 | |
| 76 | spidercls: type[Spider] = DefaultSpider |
| 77 | if opts.spider: |
| 78 | spidercls = spider_loader.load(opts.spider) |
| 79 | elif url: |
| 80 | spidercls = spidercls_for_request( |
| 81 | spider_loader, Request(url), spidercls, log_multiple=True |
| 82 | ) |
| 83 | |
| 84 | # The crawler is created this way since the Shell manually handles the |
| 85 | # crawling engine, so the set up in the crawl method won't work |
| 86 | crawler = self.crawler_process._create_crawler(spidercls) |
| 87 | crawler._apply_settings() |
| 88 | loop: asyncio.AbstractEventLoop | None = None |
| 89 | if crawler.settings.getbool("TWISTED_REACTOR_ENABLED"): |
| 90 | self._init_with_reactor(crawler) |
| 91 | else: |
| 92 | self._init_without_reactor(crawler) |
| 93 | loop = self._get_reactorless_loop() |
| 94 | shell = Shell(crawler, update_vars=self.update_vars, code=opts.code, loop=loop) |
| 95 | shell.start(url=url, redirect=not opts.no_redirect) |
| 96 | |
| 97 | def _init_with_reactor(self, crawler: Crawler) -> None: |
| 98 | # Create the engine and run start_async() in the main thread |
nothing calls this directly
no test coverage detected