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

Method run

scrapy/commands/runspider.py:46–66  ·  view source on GitHub ↗
(self, args: list[str], opts: argparse.Namespace)

Source from the content-addressed store, hash-verified

44 return "Run the spider defined in the given file"
45
46 def run(self, args: list[str], opts: argparse.Namespace) -> None:
47 if len(args) != 1:
48 raise UsageError
49 filename = Path(args[0])
50 if not filename.exists():
51 raise UsageError(f"File not found: {filename}\n")
52 try:
53 module = _import_file(filename)
54 except (ImportError, ValueError) as e:
55 raise UsageError(f"Unable to load {str(filename)!r}: {e}\n") from e
56 spclasses = list(iter_spider_classes(module))
57 if not spclasses:
58 raise UsageError(f"No spider found in file: {filename}\n")
59 spidercls = spclasses.pop()
60
61 assert self.crawler_process
62 self.crawler_process.crawl(spidercls, **opts.spargs)
63 self.crawler_process.start()
64
65 if self.crawler_process.bootstrap_failed:
66 self.exitcode = 1

Callers

nothing calls this directly

Calls 6

UsageErrorClass · 0.90
iter_spider_classesFunction · 0.90
_import_fileFunction · 0.85
popMethod · 0.45
crawlMethod · 0.45
startMethod · 0.45

Tested by

no test coverage detected