我知道这可能是一个简单的问题,但我真的需要帮助。
我试图从这个汤对象中提取每场比赛的总篮板数。
我尝试使用以下代码但出现错误:
import urllib.request
from bs4 import BeautifulSoup
import csv
url = "https://www.basketball-reference.com/players/a/abdulza01.html"
request = urllib.request.Request(url) # create request object
response = urllib.request.urlopen(request)
html = response.read().decode('unicode_escape') # convert to unicode format
soup = BeautifulSoup(html, "html.parser")
table = soup.find('table', attrs={'id': 'per_game'})
results = table.find_all('tr')
for result in results[1:len(results)]:
data = result.find_all('td')
data.find(attrs={'data-stat': 'trb_per_g'}).getText()
data = [<td class="center iz" data-stat="age"></td>,
<td class="left " data-stat="team_id"><a href="/teams/BOS/">BOS</a></td>,
<td class="left " data-stat="lg_id">NBA</td>,
<td class="center iz" data-stat="pos"></td>,
<td class="right " data-stat="g">2</td>,
<td class="right incomplete iz" data-stat="gs"></td>,
<td class="right " data-stat="mp_per_g">12.0</td>,
<td class="right " data-stat="fg_per_g">1.5</td>,
<td class="right " data-stat="fga_per_g">6.5</td>,
<td class="right " data-stat="fg_pct">.231</td>,
<td class="right " data-stat="ft_per_g">1.0</td>,
<td class="right " data-stat="fta_per_g">1.5</td>,
<td class="right " data-stat="ft_pct">.667</td>,
<td class="right " data-stat="orb_per_g">3.0</td>,
<td class="right " data-stat="drb_per_g">4.5</td>,
<td class="right " data-stat="trb_per_g">**7.5**</td>,
<td class="right " data-stat="ast_per_g">1.5</td>,
<td class="right " data-stat="stl_per_g">0.5</td>,
<td class="right " data-stat="blk_per_g">0.5</td>,
<td class="right " data-stat="tov_per_g">1.5</td>,
<td class="right " data-stat="pf_per_g">2.0</td>,
<td class="right " data-stat="pts_per_g">4.0</td>]
错误消息:AttributeError:ResultSet 对象没有属性“查找”。您可能将项目列表视为单个项目。当您打算调用 find() 时,您是否调用了 find_all()?
代码在概念上有什么问题吗?
万千封印
慕运维8079593
紫衣仙女
相关分类