2012-07-10 46 views
2

我收到此錯誤scrapyResponse對象有沒有屬性編碼,scrapy錯誤

File "/usr/lib/pymodules/python2.7/scrapy/selector/factories.py", line 20, in body_as_utf8 
    if response.encoding in utf8_encodings: 
    exceptions.AttributeError: 'Response' object has no attribute 'encoding' 

導致它只是在scrapy蜘蛛

def parse(self, response): 
    hxs = HtmlXPathSelector(response) 

我想下面的代碼解析URL

http://itunes.apple.com/WebObjects/MZStore.woa/wa/customerReviews?id=382034404%0A 

與用戶代理字符串

iTunes/10.2 (Macintosh; U; PPC Mac OS X 10.2) 

任何想法可能是什麼錯誤?我覺得奇怪,我,這個代碼總是在我其他所有的蜘蛛

回答

4

我沒有時間來調試它的工作,但我的猜測是,response說法在這種特殊情況下是不是HtmlResponseTextResponse

在回調做print response.__class__

如果該類,那麼我想它該URL返回一個非文本響應,這顯然是沒有任何encoding字節流,你不能在上面使用XPath。

2

不知道這是否超級有用,但也許它可以幫助指導你或別人。

我得到類似的錯誤:

sudo apt-get install python-pip 
sudo pip install --upgrade requests 

因此,也許你有一個依賴,提供了屬性encoding

'Response' object has no attribute 'elapsed'

它是由更新requests依賴性解決?

0

嘗試這種方式請:

def parse(self, response): 
    hxs = HtmlXPathSelector(text=response.body) 
相關問題