因此,我正在慢慢学习Python,并试图制作一个简单的函数,它将从网络游戏的高分页面中绘制数据。这是别人的代码,我重写了一个函数(这可能是问题),但我得到这个错误。这里是代码:为什么我在Python中使用BeautifulSoup时,'ResultSet'没有属性'findAll'“?
>>> from urllib2 import urlopen
>>> from BeautifulSoup import BeautifulSoup
>>> def create(el):
source = urlopen(el).read()
soup = BeautifulSoup(source)
get_table = soup.find('table', {'id':'mini_player'})
get_rows = get_table.findAll('tr')
text = ''.join(get_rows.findAll(text=True))
data = text.strip()
return data
>>> create('http://hiscore.runescape.com/hiscorepersonal.ws?user1=bigdrizzle13')
Traceback (most recent call last):
File "<pyshell#18>", line 1, in <module>
create('http://hiscore.runescape.com/hiscorepersonal.ws?user1=bigdrizzle13')
File "<pyshell#17>", line 6, in create
text = ''.join(get_rows.findAll(text=True))
AttributeError: 'ResultSet' object has no attribute 'findAll'
在此先感谢。
它的价值:命名变量“第一”,“第二”等是可怕的风格。你真的应该更具描述性 - 当然,具体名称取决于你,但我可能会使用“urlcontent”,“parser”,“mp_tables”等。 – 2009-06-14 05:09:43
它是我第三天与Python。我需要做到这一点,以保持我的头脑。随着时间的推移,这会变得更好...... – Alex 2009-06-14 05:12:33