1
でスクリプトからScrapyを実行:は、私は現在、以下のコマンドライン引数でScrapyを使用していたファイル出力
scrapy crawl my_spider -o data.json
しかし、私は、Pythonスクリプトでこのコマンドを「保存」することを好むだろう。 https://doc.scrapy.org/en/latest/topics/practices.htmlに続いて、私は次のスクリプトを持っている:
import scrapy
from scrapy.crawler import CrawlerProcess
from apkmirror_scraper.spiders.sitemap_spider import ApkmirrorSitemapSpider
process = CrawlerProcess({
'USER_AGENT': 'Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1)'
})
process.crawl(ApkmirrorSitemapSpider)
process.start() # the script will block here until the crawling is finished
しかし、それは-o data.json
コマンドライン引数の同等は、スクリプト内でどうあるべきかのドキュメントから私には不明です。スクリプトでJSONファイルを生成させるにはどうすればよいですか?あなたのCrawlerProcess
にFEED_FORMAT
とFEED_URI
を追加する必要が
[JSONでのスクリプトの出力からscrapy]の可能な重複(http://stackoverflow.com/questions/23574636/scrapy-from- script-output-in-json) – Casper
これを参照してください[answer](http://stackoverflow.com/questions/23574636/scrapy-from-script-output-in-json) –