【发布时间】:2021-12-24 10:28:41
【问题描述】:
我是使用 Beautiful Soup 进行数据抓取的新手。我想从 pro-football-reference 中获取有关这些统计数据的数据:https://www.pro-football-reference.com/boxscores/201009090nor.htm#all_pbp
我想遍历完整播放表下“详细信息列”下的每一行,以便如果详细信息包含“惩罚”一词,我可以保存它。有没有人知道我怎么可能做到这一点?这张表似乎与其他表不同。
# Any example of how I extracted another element (Referee Name)
# from the same page but different table
table = soup.select_one('#all_officials').find_next(text=lambda t: isinstance(t, Comment))
table = BeautifulSoup(table, 'html.parser')
for tr in table.select('tr'):
tds = [td.get_text(strip=True) for td in tr.select('td')]
if str(*tds) != "Officials":
referee = str(*tds)
break
【问题讨论】:
标签: python beautifulsoup