我使用以下代码从python脚本运行我的爬虫程序:
import scrapy
from scrapy.crawler import CrawlerProcess
process = CrawlerProcess()
process.crawl(MySpider)
process.start() # the script will block here until the crawling is finished我的MySpider返回一个对象。
如何从中获取返回值?请记住这是Scrapy 1.0。我找到的所有示例都是针对旧版本的Scrapy。
上面的代码来自:http://doc.scrapy.org/en/latest/topics/practices.html#run-scrapy-from-a-script
发布于 2015-07-12 20:09:37
好的,解决方案是实现自定义项管道,将结果存储在一个文件中--并在稍后读取结果。
或者,您也可以在Scrapy中配置导出。例如,导出名为results.json的文件中的项目
settings.overrides['FEED_FORMAT'] = 'json'
settings.overrides['FEED_URI'] = 'results.json'为了避免使用时态文件,您应该使用自定义管道类,并在spider_closed信号上处理结果。
有关更多详细信息,请参阅以下答案:https://stackoverflow.com/a/23574703/3941341
https://stackoverflow.com/questions/31365890
复制相似问题