MCPcopy
hub / github.com/scrapy/scrapy / run

Method run

scrapy/commands/shell.py:67–95  ·  view source on GitHub ↗
(self, args: list[str], opts: Namespace)

Source from the content-addressed store, hash-verified

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

Callers

nothing calls this directly

Calls 12

_init_with_reactorMethod · 0.95
_init_without_reactorMethod · 0.95
_get_reactorless_loopMethod · 0.95
startMethod · 0.95
guess_schemeFunction · 0.90
spidercls_for_requestFunction · 0.90
RequestClass · 0.90
ShellClass · 0.90
_apply_settingsMethod · 0.80
loadMethod · 0.45
_create_crawlerMethod · 0.45
getboolMethod · 0.45

Tested by

no test coverage detected