【发布时间】:2016-07-18 16:05:29
【问题描述】:
我正在尝试编写一些代码来从互联网上抓取财务数据,然后将其呈现为表格中的表格。我遇到的问题是我一直返回一个错误,上面写着 - AttributeError: 'ResultSet' object has no attribute 'findAll' 我不知道为什么它会一直返回这个,我已经尝试了很多方法来摆脱这个错误,但它只是不断地回来。我希望这里的一些人能够对这种情况有所了解。我的代码如下:
import urllib2
from bs4 import BeautifulSoup
Goog_page = 'https://uk.finance.yahoo.com/q/hp?s=GOOG'
page = urllib2.urlopen(Goog_page)
html = page.read()
soup = BeautifulSoup(html, "lxml")
soup.prettify().encode('UTF-8')
#print soup.findAll('table')
right_table = soup.find_all('table', {'class':'yfnc_datamodoutline1'})
A=[]
B=[]
C=[]
D=[]
E=[]
F=[]
G=[]
H=[]
I=[]
J=[]
def parse_string(el):
text = ''.join(el.findAll(text=True))
return text.strip()
for rows in right_table:
rows = map(parse_string, right_table.findAll('tr'))
for cell in rows:
data = map(parse_string, rows.findAll('td'))
if len(data)>1:
A.append(data[0].find(text=True))
B.append(data[1].find(text=True))
C.append(data[2].find(text=True))
D.append(data[3].find(text=True))
E.append(data[4].find(text=True))
F.append(data[5].find(text=True))
G.append(data[6].find(text=True))
H.append(data[7].find(text=True))
I.append(data[8].find(text=True))
J.append(data[9].find(text=True))
我返回的错误是:文件“...”,第 37 行,行 = right_table.findAll('tr'),然后打印错误消息。
我正在使用 python 2.7 和 windows 8.1
提前感谢您的帮助!
【问题讨论】:
-
好的,谢谢。我去看看!
标签: python beautifulsoup