プログラミング初心者です。スクレインピングで楽天イーグルスのデータを取得しようとしています。以下のようなコードで選手のプロフィールの書いてあるURLを取得し、それをリストに入れようとしたのですが下記のエラーが発生してしまいました。原因と解決策を教えて欲しいです。google.colabにて実行しています。
[書いたコード]
import time
import requests
from bs4 import BeautifulSoup as bs
url = []
url = 'https://www.rakuteneagles.jp/team/player/list/index.html'
r = requests.get(url)
html = bs(r.text,'html.parser')
html_select = html.select('main > section > div > div > section > ul > li > a')
for div in html_select:
player_url = 'https://www.rakuteneagles.jp' + div.get('href')
url.append(div)
[起きたエラー]
AttributeError Traceback (most recent call last)
<ipython-input-83-77a50a2baea5> in <module>()
2 for div in html_select:
3 player_url = 'https://www.rakuteneagles.jp' + div.get('href')
----> 4 url.append(div)
5 print(player_url)
6 # player_htmldata = requests.get(player_url)
AttributeError: 'str' object has no attribute 'append'
回答1件
あなたの回答
tips
プレビュー