簡體   English   中英

AttributeError:“系列”對象使用熊貓沒有屬性“ get_type”

[英]AttributeError: 'Series' object has no attribute 'get_type' using pandas

我試圖使用我在csv文件中駐留的先前腳本中抓取的網站代碼,以創建可以使用xpath抓取的網址。 這些值在csv的“鏈接”列中。 我在第32行專門遇到以下錯誤

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()')`

您的可變url是一個系列,而不是字符串。 初始化imdbcode ,它是一系列鏈接,並且pandas在啟動時會在每一行中廣播字符串添加。

我不確定是否沒有看到其他東西,但是你想要

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

而是只獲取字符串值。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM