如何使用python的Beauty soup获取团队文本和分数?

如何使用python的Beauty soup获取团队文本和分数?,python,python-3.x,web-scraping,beautifulsoup,Python,Python 3.x,Web Scraping,Beautifulsoup,我试图获得所有的队与队的信息和分数,这是一个显示按钮下隐藏使用此url。我试图得到OPP1对OPP2以及比赛结果。。这就是我到目前为止解决这个问题的方法 def all_match_outcomes(): for match_outcomes in all_match_history_url(): page = requests.get(match_outcomes).content soup = BeautifulSoup(page, 'html.pa

我试图获得所有的队与队的信息和分数,这是一个显示按钮下隐藏使用此url。我试图得到OPP1对OPP2以及比赛结果。。这就是我到目前为止解决这个问题的方法

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
没有“隐藏”,它不是浏览器)。主场得分在
span
hscore
类中,客场得分在
span
ascore类中。团队名称位于具有
opp1
opp2
类的
span
元素中的内部
elements下。实施:

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

查看页面的源代码,您将看到您需要的所有信息都在一个带有类
简单游戏列表配置文件列表的表中

阅读文章,尤其是find方法


尝试在html源代码中查找模式,您将快速了解如何迭代每个表数据(
)以及如何提取团队等。

请显示您目前拥有的代码以及哪些代码不起作用。是否足够清楚,或者我是否应该添加所有代码?我还尝试显示两个团队的名称,有两个span标记,团队文本位于第二个span中。我该如何获得球队名称?@DJRodrigue答案中已经有了,10分钟前更新了它,以获得球队名称。希望有帮助。是的,对不起,我没有刷新。非常感谢。