我正在尝试从足球比赛中获取 Opta 事件数据。它有一个链接地址,但当尝试访问它时,我只收到 10300 错误代码。
我可以查看数据的唯一位置是开发工具中的“源”下,位于名为 api.performfeeds.com 的文件夹下。如何使用 selenium 访问源?
我尝试过 api 请求和许多其他东西。我可以抓取大多数其他数据网站,但这个(scoresway.com)很棘手。
要使用 Selenium 从足球比赛中抓取 Opta 事件数据,您可以按照以下步骤操作:
以下是如何使用 Selenium 访问“源”选项卡并从 API 端点提取数据的基本示例:
from selenium import webdriver
# Initialize Selenium WebDriver
driver = webdriver.Chrome()
# Open the website containing the Opta event data
driver.get("URL_OF_THE_WEBSITE")
# Navigate to the 'Sources' tab in the developer tools
driver.execute_script("window.open('chrome-devtools://devtools/bundled/inspector.html')")
dev_tools_window = driver.window_handles[-1]
driver.switch_to.window(dev_tools_window)
# Now you should be in the 'Sources' tab. Locate the API endpoint and extract the data.
# You can use Selenium's find_element_* methods to locate elements on the page and retrieve the API endpoint.
# Once you have the API endpoint, you can use Python's requests library to make the request and retrieve the data.
# Don't forget to close the WebDriver once you're done
driver.quit()
请记住将 URL_OF_THE_WEBSITE 替换为包含 Opta 事件数据的网站的实际 URL。