java从网页抓取数据(丹杰我正在尝试从这个网站上抓取第二个表或告诉我如何做 )
优采云 发布时间: 2021-12-19 03:04java从网页抓取数据(丹杰我正在尝试从这个网站上抓取第二个表或告诉我如何做
)
单节
我试图从这个 网站 中获取第二个表: 但是,我只设法从提取时获取了第一个表信息,尝试通过查找表标签来访问信息。谁能向我解释为什么我无法访问第二个表或告诉我该怎么做。
import requests
from bs4 import BeautifulSoup
url = "https://fbref.com/en/comps/9/stats/Premier-League-Stats"
res = requests.get(url)
soup = BeautifulSoup(res.text, 'lxml')
pl_table = soup.find_all("table")
player_table = tables[0]
安德烈·凯斯利
表格在 HTML 注释中。
要从评论中获取表单,您可以使用以下示例:
<p>import requests
from bs4 import BeautifulSoup, Comment
url = 'https://fbref.com/en/comps/9/stats/Premier-League-Stats'
soup = BeautifulSoup(requests.get(url).content, 'html.parser')
table = BeautifulSoup(soup.select_one('#all_stats_standard').find_next(text=lambda x: isinstance(x, Comment)), 'html.parser')
#print some information from the table to screen:
for tr in table.select('tr:has(td)'):
tds = [td.get_text(strip=True) for td in tr.select('td')]
print('{: