python - Scrapy process.crawl() 导出数据到json

标签 python json scrapy web-crawler

这可能是 Passing arguments to process.crawl in Scrapy python 的子问题但作者将答案(没有回答我问自己的子问题)标记为令人满意的答案。

这是我的问题:我无法使用 scrapy crawl mySpider -a start_urls(myUrl) -o myData.json
相反,我想/需要使用 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()

关于python - Scrapy process.crawl() 导出数据到json,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37876514/

相关文章:

python - Geopy 在 ASCII 字符上阻塞

android - 使用 sencha 创建 Android 应用程序时出错

python - 从scrapy的多个类中获取文本

python - scrapy中 'slot'是什么意思?

python - 将内容直接发送到 scrapy pipeline

python - 使用 Python 直接从 zip 文件中读取 xml 文件

python - Python Twitter Tools-处理Twitter 404和401 API错误

python - 使用 venv 中的库从命令行运行 Python 文件

java - 从 spring mvc Controller 返回一个简单的映射结构到 ajax

python - 使用anytree将JSON转换为图像