私はPythonをゆっくり学び、オンラインゲームのハイスコアページからデータを引き出すシンプルな関数を作ろうとしています。これは私が1つの関数(問題の可能性があります)に書き換えた他の人のコードですが、このエラーが発生しています。コードは次のとおりです。なぜ「ResultSet」にPythonのBeautifulSoupを使用した属性「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'
ありがとうございます。
変数の名前を "first"、 "second"などと命名するのは恐ろしいスタイルです。具体的な名前はあなた次第ですが、 "urlcontent"、 "parser"、 "mp_tables"などを使用することもできます。 –
私の3日目はPythonです。私はそれを私の頭の中でまっすぐに保つためにそれをする必要があります。それは時間が経つにつれて良くなるでしょう... – Alex
私は変数名を変更しました。希望はそれより良い。 – Alex