2017-10-05 78 views
0

其實我想將與特定網站相關的所有數據(文本,hrefs,圖像)存儲到一個文件夾中。爲了做到這一點,我需要傳遞該文件夾的路徑所有不同的解析function.So我想通過在scrapy.Request()這樣這條道路作爲額外kwargs:將附加參數傳遞給scrapy.Request()

yield scrapy.Request(url=url,dont_filter=True, callback=self.parse,errback = self.errback_function,kwargs={'path': '/path/to_folder'})

但它給錯誤TypeError: __init__() got an unexpected keyword argument 'kwargs'

我怎麼能傳遞路徑下一個函數?

+3

你可以用'meta'參數傳遞額外參數。 https://doc.scrapy.org/en/latest/topics/request-response.html#request-objects – AndMar

+0

是的,我也想到了這件事。但是你確定這是正確的嗎? – amrit

+1

是的,我確定。這只是一個正確的方法 – AndMar

回答

2

的人誰需要它......

可以使用元參數這樣傳遞額外的參數...

yield scrapy.Request(url=url,dont_filter=True, callback=self.parse,errback = self.errback_function, meta={'filepath': filepath})