Scrapy process.crawl() 将数据导出到 json
Scrapy process.crawl() to export data to json
这可能是 的子问题,但作者将答案(没有回答我问自己的子问题)标记为令人满意的答案。
这是我的问题:我无法使用 scrapy crawl mySpider -a start_urls(myUrl) -o myData.json
相反,我 want/need 使用 crawlerProcess.crawl(spider)
我已经想出了几种传递参数的方法(无论如何它在我链接的问题中得到了回答)但我无法理解我应该如何告诉它将数据转储到 myData.json... -o myData.json
部分
有人有建议吗?或者我只是不明白它应该如何工作..?
这是代码:
crawlerProcess = CrawlerProcess(settings)
crawlerProcess.install()
crawlerProcess.configure()
spider = challenges(start_urls=["http://www.myUrl.html"])
crawlerProcess.crawl(spider)
#For now i am just trying to get that bit of code to work but obviously it will become a loop later.
dispatcher.connect(handleSpiderIdle, signals.spider_idle)
log.start()
print "Starting crawler."
crawlerProcess.start()
print "Crawler stopped."
需要在设置中指定:
process = CrawlerProcess({
'FEED_URI': 'file:///tmp/export.json',
})
process.crawl(MySpider)
process.start()
这可能是
这是我的问题:我无法使用 scrapy crawl mySpider -a start_urls(myUrl) -o myData.json
相反,我 want/need 使用 crawlerProcess.crawl(spider)
我已经想出了几种传递参数的方法(无论如何它在我链接的问题中得到了回答)但我无法理解我应该如何告诉它将数据转储到 myData.json... -o myData.json
部分
有人有建议吗?或者我只是不明白它应该如何工作..?
这是代码:
crawlerProcess = CrawlerProcess(settings)
crawlerProcess.install()
crawlerProcess.configure()
spider = challenges(start_urls=["http://www.myUrl.html"])
crawlerProcess.crawl(spider)
#For now i am just trying to get that bit of code to work but obviously it will become a loop later.
dispatcher.connect(handleSpiderIdle, signals.spider_idle)
log.start()
print "Starting crawler."
crawlerProcess.start()
print "Crawler stopped."
需要在设置中指定:
process = CrawlerProcess({
'FEED_URI': 'file:///tmp/export.json',
})
process.crawl(MySpider)
process.start()