我正在尝试从网页中的tbody提取数据。我可以访问tbody部分,但是出现了一个空查询。我该如何解决?谢谢。我的预期输出像是tr和td都进入了这个tbody,但是什么也没得到:<tbody class="matchCentreStatsContainer"></tbody>
import requests
from bs4 import BeautifulSoup
Abs_Conc = []
url = 'https://www.premierleague.com/match/46605'
res = requests.get(url)
html_page = res.content
soup = BeautifulSoup(html_page, 'html.parser')
try:
Tbody = soup.find('div', {'class': 'matchCentre'}).find('section', {'class': 'mcContent'}).find('div', {'class': 'centralContent'}).find('div', {'class': 'mcTabsContainer'}).find('section', {'class': 'mcMainTab head-to-head'}).find('div', {'class': 'mcStatsTab statsSection season-so-far wrapper col-12'}).select('tbody', {'class': 'matchCentreStatsContainer'})
先询问漂亮的汤,先单击主页上的“统计信息”标签,因为它不在您的代码查找的主页上,它仅是“最新的”。
统计资料
<div role="button"
class="navLink mobile " tabindex="index">
<span class="navText">Stats</span>
<span class="icn chevron-dropdown"></span>
或者您可以尝试以下代码行(因为拥有率在此类中:)>
try:
Tbody = soup.select(url, {'class': 'higher'})