有人可以解释之间的区别 runspider 和 爬行 命令?应该使用它们的背景是什么?
有人可以解释之间的区别 runspider 和 爬行 命令?应该使用它们的背景是什么?
在命令中:
scrapy crawl [options] <spider>
<spider>
是项目名称(在settings.py中定义,如 BOT_NAME
)。
在命令中:
scrapy runspider [options] <spider_file>
<spider_file>
是包含蜘蛛的文件的路径。
否则,选项是相同的:
Options
=======
--help, -h show this help message and exit
-a NAME=VALUE set spider argument (may be repeated)
--output=FILE, -o FILE dump scraped items into FILE (use - for stdout)
--output-format=FORMAT, -t FORMAT
format to use for dumping items with -o
Global Options
--------------
--logfile=FILE log file. if omitted stderr will be used
--loglevel=LEVEL, -L LEVEL
log level (default: DEBUG)
--nolog disable logging completely
--profile=FILE write python cProfile stats to FILE
--lsprof=FILE write lsprof profiling stats to FILE
--pidfile=FILE write process ID to FILE
--set=NAME=VALUE, -s NAME=VALUE
set/override setting (may be repeated)
--pdb enable pdb on failure
以来 runspider
不依赖于 BOT_NAME
您可能会发现,根据您自定义刮刀的方式,参数 runspider
更灵活。
两者的小解释和语法:
runspider
句法: scrapy runspider <spider_file.py>
需要项目:没有
在Python文件中运行自包含的蜘蛛,而无需创建项目。
用法示例:
$ scrapy runspider myspider.py
爬行
句法: scrapy crawl <spider>
需要项目:是的
使用具有相应名称的蜘蛛开始抓取。
用法示例:
$ scrapy crawl myspider
主要区别在于 runspider
不需要项目。也就是说,你可以写一个蜘蛛 myspider.py
文件和电话 scrapy runspider myspider.py
。
该 crawl
命令需要一个项目才能找到项目的设置,从中加载可用的蜘蛛 SPIDER_MODULES
设置,并查找蜘蛛 name
。
如果您需要快速蜘蛛执行短期任务,那么 runspider
需要更少的样板。
在命令中:
scrapy crawl [options] <spider>
<spider>
是项目名称(在settings.py中定义,如 BOT_NAME
)。
在命令中:
scrapy runspider [options] <spider_file>
<spider_file>
是包含蜘蛛的文件的路径。
否则,选项是相同的:
Options
=======
--help, -h show this help message and exit
-a NAME=VALUE set spider argument (may be repeated)
--output=FILE, -o FILE dump scraped items into FILE (use - for stdout)
--output-format=FORMAT, -t FORMAT
format to use for dumping items with -o
Global Options
--------------
--logfile=FILE log file. if omitted stderr will be used
--loglevel=LEVEL, -L LEVEL
log level (default: DEBUG)
--nolog disable logging completely
--profile=FILE write python cProfile stats to FILE
--lsprof=FILE write lsprof profiling stats to FILE
--pidfile=FILE write process ID to FILE
--set=NAME=VALUE, -s NAME=VALUE
set/override setting (may be repeated)
--pdb enable pdb on failure
以来 runspider
不依赖于 BOT_NAME
您可能会发现,根据您自定义刮刀的方式,参数 runspider
更灵活。
两者的小解释和语法:
runspider
句法: scrapy runspider <spider_file.py>
需要项目:没有
在Python文件中运行自包含的蜘蛛,而无需创建项目。
用法示例:
$ scrapy runspider myspider.py
爬行
句法: scrapy crawl <spider>
需要项目:是的
使用具有相应名称的蜘蛛开始抓取。
用法示例:
$ scrapy crawl myspider
主要区别在于 runspider
不需要项目。也就是说,你可以写一个蜘蛛 myspider.py
文件和电话 scrapy runspider myspider.py
。
该 crawl
命令需要一个项目才能找到项目的设置,从中加载可用的蜘蛛 SPIDER_MODULES
设置,并查找蜘蛛 name
。
如果您需要快速蜘蛛执行短期任务,那么 runspider
需要更少的样板。