多个爬虫:
from scrapy.crawler import CrawlerProcess
from scrapy.utils.project import get_project_settings
# 根据项目配置获取 CrawlerProcess 实例
process = CrawlerProcess(get_project_settings())
# 添加需要执行的爬虫
process.crawl('route')
process.crawl('dining')
process.crawl('experience')
# 执行
process.start()
如果需要向某个爬虫传递参数,可以在 process.crawl
方法中添加进去,例如:
# 如果需要向某个爬虫传递参数,可以在process.crawl方法中添加进去,例如:
process.crawl('dining', dt='20191119')
# 则在dining这个爬虫(类)中,可以在__init__方法中接收这个dt参数。例如:
class Dining(scrapy.Spider):
name = 'dining'
def __init__(self, dt)
self.dt = dt