gpt4 book ai didi

python - 如何使用 Beautiful soup 和 python 获取团队文本和得分?

转载 作者:太空宇宙 更新时间:2023-11-03 16:28:46 25 4
gpt4 key购买 nike

我正在尝试使用此网址 http://www.gosugamers.net/counterstrike/teams/7397-natus-vincere/matches 获取隐藏在显示按钮下的所有球队与球队信息以及得分。我正在尝试获取 opp 1 vs opp 2 以及游戏的结果。这就是我迄今为止针对此问题所得到的结果。

def all_match_outcomes():

for match_outcomes in all_match_history_url():
page = requests.get(match_outcomes).content
soup = BeautifulSoup(page, 'html.parser')

for match_outcome in soup.select_one('div table.simple.gamelist.profilelist td'):
opp_1 = match_outcome.select_one('a').find('span')
print(opp_1)

最佳答案

游戏结果位于隐藏范围内(好吧,BeautifulSoup 没有“隐藏”,它不是浏览器)。主场得分位于带有 hscore 类的 span 中,客场得分位于带有 ascore 类的 span 中。团队名称位于带有 opp1opp2 类的 span 元素内的内部 span 元素下。实现:

import requests
from bs4 import BeautifulSoup


match_outcomes = "http://www.gosugamers.net/counterstrike/teams/7397-natus-vincere/matches"
page = requests.get(match_outcomes).content
soup = BeautifulSoup(page, 'html.parser')

for row in soup.select('table.simple.gamelist.profilelist tr'):
opp1 = row.find("span", class_="opp1").span.get_text()
opp2 = row.find("span", class_="opp2")("span")[-1].get_text()

opp1_score = row.find("span", class_="hscore").get_text()
opp2_score = row.find("span", class_="ascore").get_text()

print("%s %s:%s %s" % (opp1, opp1_score, opp2_score, opp2))

打印:

Virtus.Pro.CS 2:1 Natus Vincere
Dobry&Gaming; 0:2 Natus Vincere
GODSENT 0:2 Natus Vincere
HellRaisers 0:2 Natus Vincere
Flipsid3 Tactics 1:2 Natus Vincere
Natus Vincere 1:2 Dobry&Gaming;
mousesports.CS 1:0 Natus Vincere
mousesports.CS 0:1 Natus Vincere
...
Natus Vincere 2:1 Flipsid3 Tactics
Team Dignitas.CS 0:1 Natus Vincere

关于python - 如何使用 Beautiful soup 和 python 获取团队文本和得分?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37778589/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com