2017-10-13 44 views
0

我想使用網站代碼,我在先前的腳本中駐留在我的csv文件中,以創建網址,我可以使用xpath進行搜索。這些值位於csv中的「鏈接」列中。我遇到了以下錯誤專門針對線32AttributeError:'系列'對象沒有使用熊貓的屬性'get_type'

File "Willisp3.py", line 32, in <module> 
uClient = uReq(url) 
File "/Users/gil/anaconda/lib/python2.7/urllib2.py", line 154, in 
urlopen 
return opener.open(url, data, timeout) 
File "/Users/gil/anaconda/lib/python2.7/urllib2.py", line 421, in 
open 
protocol = req.get_type() 
File "/Users/gil/anaconda/lib/python2.7/site- 
packages/pandas/core/generic.py", line 2970, in __getattr__ 
return object.__getattribute__(self, name) 
AttributeError: 'Series' object has no attribute 'get_type' 

這裏是我的代碼

`filename = 'links.csv' 
df = pd.read_csv(filename) 
imdbcode = df['link'] 


for index, row in df.iterrows(): 
    url = ('https://www.imdb.com/title/' + imdbcode + '/reviews?ref_=tt_urv') 
    uClient = uReq(url) 
    content = uClient.read() 
    uClient.close() 
    page_soup = soup(content, "html.parser") 
    page_soup = soup(content, "lxml-xml") 
    page = requests.get(url) 
    stuff2 = html.fromstring(page.content) 
    comment = stuff2.xpath('//div[@id="tn15content"]/p/text()')[0] 
    title = stuff2.xpath('//div[@id="tn15title"]/h1/a/text()')` 
+0

什麼是32行?你爲什麼不向我們展示整個回溯。 –

+0

剛加入。我很抱歉沒有它在第一次。 –

+0

錯誤發生在函數'uReq'上,但'uReq'沒有被定義或導入到代碼中的任何地方。 –

回答

0

你的變量url是一個系列,而不是一個字符串。當您初始化imdbcode時,它是一系列鏈接,當您啓動它時,熊貓將在每行中廣播字符串添加。

我不能確切地知道,沒有看到其他的東西,但你要

url = 'https://http://www.imdb.com/title/' + row['link'] + '/reviews?ref_=tt_urv' 

,而不是隻獲取字符串值。

+0

太棒了。這爲我解決了它。謝謝! –

+0

嘿@GilbertLee,很高興爲你工作。如果你不介意接受我的回答,我會很感激 – breucopter

相關問題