Mar*_*oli 1 python json scrapy python-2.7
我通常会像这样叫我的蜘蛛:
scrapy crawl Spider -o fileName -t json
Run Code Online (Sandbox Code Playgroud)
并且我在fileNamejson格式化的文件中打印了正确的数据.
现在我想像这样叫我的蜘蛛:
scrapy crawl Spider
Run Code Online (Sandbox Code Playgroud)
有没有办法将输出打印到文件而不使用-o -t参数?
是的,可以做到.将其添加到您的设置中
FEED_EXPORTERS = {
'jsonlines': 'scrapy.contrib.exporter.JsonLinesItemExporter',
}
FEED_FORMAT = 'jsonlines'
FEED_URI = "NAME_OF_FILE.json"
Run Code Online (Sandbox Code Playgroud)
以供参考
http://doc.scrapy.org/en/latest/topics/feed-exports.html