我很新手,我在使用cookie的網絡中使用scrapy,這對我來說是一個問題,因爲我可以在不使用cookie的情況下獲取網絡數據,但是用cookies來獲取網絡的數據對我來說是非常困難的。 我有這樣的代碼結構什麼是在scrapy中使用cookie的正確工作形式
class mySpider(BaseSpider):
name='data'
allowed_domains =[]
start_urls =["http://...."]
def parse(self, response):
sel = HtmlXPathSelector(response)
items = sel.xpath('//*[@id=..............')
vlrs =[]
for item in items:
myItem['img'] = item.xpath('....').extract()
yield myItem
這是好的,我可以得到精細的數據,而無需使用該代碼的結構 我發現它,因爲我可以用Cookie的工作,在這個網址餅乾,但我不明白的地方我應該把這個代碼,然後就可以使用XPath
獲取數據我測試這個代碼
request_with_cookies = Request(url="http://...",cookies={'country': 'UY'})
,但我不知道,我可以工作,或者把這個代碼, 我把這個公司德成函數解析,對獲得的數據
def parse(self, response):
request_with_cookies = Request(url="http://.....",cookies={'country':'UY'})
sel = HtmlXPathSelector(request_with_cookies)
print request_with_cookies
我嘗試使用XPath與餅乾這個新網址,供以後打印這個新的數據刮 我還以爲是像一個URL工作沒有cookies 但當我運行這個我有一個錯誤,因爲'請求'對象沒有屬性'body_as_unicode' 什麼是正確的方式來使用這些cookie,我有點迷路 非常感謝。