crawl a list of sites one by one with scrapy

∥☆過路亽.° 提交于 2020-01-15 10:33:51

问题


I am trying to crawl a list of sites with scrapy. I tried to put the list of website urls as the start_urls, but then I found I couldn't afford so much memory with it. Is there any way to set the scrapy crawling one or two sites at a time?


回答1:


You can try using concurrent_requests = 1 so that you don't overloaded with data

http://doc.scrapy.org/en/latest/topics/settings.html#concurrent-requests




回答2:


You can define a start_requests method which iterates through requests to your URLs. This should avoid the overhead of holding all your start urls in memory at once and is the simplest approach to solve the problem you described.

If this is still a lot of URLs for scrapy to hold in memory during the crawl, you can enable persistence support.

If you really want to only feed scrapy a few URLs at a time, this is possible by registering for the spider_idle signal and in you callback function add the next few URLs and raise DontCloseSpider.



来源:https://stackoverflow.com/questions/14297011/crawl-a-list-of-sites-one-by-one-with-scrapy

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