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?
相关问题
- how to define constructor for Python's new Nam
- streaming md5sum of contents of a large remote tar
- How to get the background from multiple images by
- Evil ctypes hack in python
- Correctly parse PDF paragraphs with Python
You can try using
concurrent_requests = 1
so that you don't overloaded with datahttp://doc.scrapy.org/en/latest/topics/settings.html#concurrent-requests
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.