scrapy可以進行線性/順序抓取嗎?

def parse(response):
for url in urls:
yield Request(url, callback = other_parse)
yield Request(next_url, callback = parse)
結構類似上述例子的爬蟲可不可以實現順序抓取數據?


簡單的順序需求,可以在抓取抓取完 A 後,拋出 B;
複雜些的需求,自己使用隊列管理吧。


你寫的例子不能http://doc.scrapy.org/en/latest/intro/overview.html?highlight=asynchronously:

requests are scheduled and processed asynchronously. This means that Scrapy doesn』t need to wait for a request to be finished and processed, it can send another request or do other things in the meantime.

scrapy非同步處理Request請求,Scrapy發送請求之後,不會等待這個請求的響應,可以同時發送其他請求或者做別的事情。

現在的 Scrapy "Request" 了一個 priority 屬性, Requests and Responses
所以 ,這樣

for url in urls:
yield Request(url, callback = other_parse, priority = 1)
yield Request(next_url, callback = parse, priority = 0)

(數字越大,優先順序越高, 默認為0),scrapy 保證按優先順序順序處理 Request 請求, 但是我不確定回調函數是否按順序返回


最簡單的解決方法是:disable concurrency 在 settings 或者設置一個延遲


推薦閱讀:

python爬蟲的中文亂碼問題?
如何解決Python selenium在遠程shell下無法連接瀏覽器的問題?
如何在 python 中使用 beautifulsoup4 來抓取標籤中的內容?
按鍵精靈等以GUI介面為基礎的程序在爬蟲界的地位是怎樣的?
用 Scrapy 爬蟲怎麼解決動態網頁的問題?

TAG:Python | 爬蟲計算機網路 | scrapy |