问题
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