我想使用網站代碼,我在先前的腳本中駐留在我的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()')`
什麼是32行?你爲什麼不向我們展示整個回溯。 –
剛加入。我很抱歉沒有它在第一次。 –
錯誤發生在函數'uReq'上,但'uReq'沒有被定義或導入到代碼中的任何地方。 –