提问人:codedbyjosh 提问时间:8/19/2023 最后编辑:Barmarcodedbyjosh 更新时间:8/19/2023 访问量:30
使用 Python 从 URL 中提取数据
Extract Data from A URL with Python
问:
我正在尝试使用 Python 和 BeautifulSoup 从网站中提取数据。我需要的数据在表格中。
我知道如何使用 .但是,此页上有多个具有相同类名的表。通过id选择表的代码是什么。soup.select('table.class_name')
html 是
<table class="stats_table sortable min_width now_sortable sticky_table eq1 re1 le1 is_sorted" id="matchlogs_for" data-cols-to-freeze=",1">
我尝试的代码
team1_link = team_links[0]
data = urlopen(team1_link,)
soup = BeautifulSoup(data, 'html.parser')
table = soup.select('table.stats_table')
有多个类名为“stats_table”的表,所以我得到了错误的数据
答: 暂无答案
评论
soup.select('table#matchlogs_for')
将按 ID 选择。soup.find(id="matchlogs_for")
.
#