scrapy is there a way to print json file without using -o -t parameters

情到浓时终转凉″ 提交于 2021-01-28 05:55:45

问题


I am usually calling my spider like this:

scrapy crawl Spider -o fileName -t json

and I got the correct data printed in the fileName file as json formated.

Now I want to call my spider like this:

scrapy crawl Spider

my question

is there a way to print the output to a file without using the -o -t parameters?


回答1:


Yes it can be done. add this to your settings

FEED_EXPORTERS = {
 'jsonlines': 'scrapy.contrib.exporter.JsonLinesItemExporter',
}
FEED_FORMAT = 'jsonlines'
FEED_URI = "NAME_OF_FILE.json"

For reference

http://doc.scrapy.org/en/latest/topics/feed-exports.html



来源:https://stackoverflow.com/questions/21933414/scrapy-is-there-a-way-to-print-json-file-without-using-o-t-parameters

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!