到目前为止,我的代码适用于 FBref 网站上的不同表格,但难以获取玩家详细信息。下面的代码:
import requests
from bs4 import BeautifulSoup, Comment
url = 'https://fbref.com/en/squads/18bb7c10/Arsenal-Stats'
soup = BeautifulSoup(requests.get(url).content, 'html.parser')
table = BeautifulSoup(soup.select_one('#stats_standard').find_next(text=lambda x: isinstance(x, Comment)), 'html.parser')
#print some information from the table to screen:
for tr in table.select('tr:has(td)'):
tds = [td.get_text(strip=True) for td in tr.select('td')]
print('{:<30}{:<20}{:<10}'.format(tds[0], tds[3], tds[5]))
给我错误
AttributeError: 'NoneType' object has no attribute 'find_next'