python - BeautifulSoup 运动刮刀返回空列表
问题描述
我正在尝试使用 Python 的 BeautifulSoup从这个网站上抓取网球比赛的结果。我已经尝试了很多东西,但我总是得到一个空列表。我犯了一个明显的错误吗?当我检查它时,网站上有这个类的多个实例,但它似乎没有找到它。
import requests
from bs4 import BeautifulSoup
url = 'https://www.flashscore.com/tennis/atp-singles/french-open/results/'
page = requests.get(url)
soup = BeautifulSoup(page.content, 'html.parser')
match_container = soup.find_all('div', class_='event__match event__match--static event__match--last event__match--twoLine')
print(match_container)
解决方案
乐谱数据被动态拉入页面,您只获得带有请求的初始 HTML。
正如用户 70 在评论中建议的那样,这样做的方法是首先使用像 Selenium 这样的工具,这样您就可以获得在 Web 浏览器的检查工具中看到的所有动态内容。
网上很少有指南展示它是如何工作的——你可以从这个开始:
推荐阅读
- javascript - 异步加载数据,一键下载CSV数据,比最新检索数据落后一步
- javascript - node/fastify 不支持的媒体类型出现错误:application/x-www-form-urlencoded
- visual-studio - 我想为 Visual Studio 中的每个构建增加构建修订版本
- python - 如何设置整个 QTableWidget 的边框颜色,而不是项目
- linux - GCP VM 实例中的进程自动终止
- pdf - AppleScript/Automator:使用此 PDF 的提取文本内容重命名 PDF
- subdomain - 具有域指向的经销商 Web 应用程序
- oauth-2.0 - 从 3rd 方 API 获取令牌后,我应该生成自己的令牌吗?
- react-native - 使用官方文档创建一个演示 react-native 应用程序
- entity-framework - .Net Core EF re 包括手段