首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >试图提取足球数据

试图提取足球数据
EN

Stack Overflow用户
提问于 2020-05-22 08:21:10
回答 1查看 305关注 0票数 1

我试图从以下表格的每一次匹配中提取信息。我可以访问这个实体,但是不知道如何继续。

代码语言:javascript
运行
复制
<tbody class="matchCentreStatsContainer"><tr><td><p class="higher">64.6</p></td><td><p>Possession %</p></td><td><p class="">35.4
</p></td></tr><tr><td><p class="higher">7</p>
</td><td><p>Shots on target</p></td>
<td><p class="">1</p></td></tr><tr><td><p class="higher">15</p></td><td><p>Shots</p>
</td><td><p class="">4</p></td></tr><tr><td><p class="higher">757</p></td>
<td><p>Touches</p></td><td><p class="">510</p></td></tr>
<tr><td><p class="higher">543</p></td><td><p>Passes</p></td><td><p class="">301</p></td></tr>
<tr><td><p class="higher">24</p></td><td><p>Tackles</p></td><td><p class="">23</p></td></tr>
<tr><td><p class="">12</p></td><td><p>Clearances</p></td><td><p class="higher">22</p></td></tr>
<tr><td><p class="higher">9</p></td><td><p>Corners</p></td><td><p class="">0</p></td></tr>
<tr><td><p class="">3</p></td><td><p>Offsides</p></td><td><p class="higher">2</p></td></tr>
<tr><td><p class="">2</p></td><td><p>Yellow cards</p></td><td><p class="higher">1</p></td></tr>
<tr><td><p class="">15</p></td><td><p>Fouls conceded</p></td><td><p class="higher">12</p></td></tr></tbody>

我有下面的代码来访问它,并且不能从那里移动。任何帮助提取的数据,如通行证,触摸,拥有,等等,将不胜感激。

代码语言:javascript
运行
复制
import requests
import pandas as pd
url = "https://www.premierleague.com/match/46889"
page = requests.get(url)
import bs4
soup = bs4.BeautifulSoup(page.content, 'lxml')
tablediv = soup.find(name='div', attrs={'data-ui-tab':'Match Stats'})
tablediv.tbody
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2020-05-24 02:10:21

此站点使用Rest从客户端获取数据。你需要打电话:

代码语言:javascript
运行
复制
GET https://footballapi.pulselive.com/football/stats/match/{matchID}

结果是JSON数据,您可以通过查看data字段获得统计数据,stats对象通过两个团队的id进行索引:

代码语言:javascript
运行
复制
import requests
import json

matchID = "46889"
match = requests.get(
    f"https://footballapi.pulselive.com/football/stats/match/{matchID}",
    headers = {
        "origin": "https://www.premierleague.com"
    }
)
data = json.loads(match.text)

teams = [(t["team"]["id"], t["team"]["name"]) for t in data["entity"]["teams"]]

print(teams)

for t in teams:
    print(f"stats for team {t[1]} with id {t[0]}")
    stats = data["data"][str(t[0])]
    print(stats)
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/61950709

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档