我试图从以下表格的每一次匹配中提取信息。我可以访问这个实体,但是不知道如何继续。
<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>我有下面的代码来访问它,并且不能从那里移动。任何帮助提取的数据,如通行证,触摸,拥有,等等,将不胜感激。
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发布于 2020-05-24 02:10:21
此站点使用Rest从客户端获取数据。你需要打电话:
GET https://footballapi.pulselive.com/football/stats/match/{matchID}结果是JSON数据,您可以通过查看data字段获得统计数据,stats对象通过两个团队的id进行索引:
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)https://stackoverflow.com/questions/61950709
复制相似问题