【发布时间】:2021-07-01 18:20:00
【问题描述】:
我想从这个页面的图表中抓取数据:http://188.166.44.172/match/live-stats/100941310
我尝试了 requests 和 bs4,但未能获取任何数据,我也尝试了 selenium,但也没有数据。
这是使用请求的代码:
import requests
from bs4 import BeautifulSoup
headers = {'User-Agent': 'Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:76.0) Gecko/20100101 Firefox/76.0'}
session = requests.Session()
r = session.get(u, timeout=30, headers=headers)
soup = BeautifulSoup(r.content, 'html.parser')
for i in soup.find_all('rect'):
if i.has_attr("onmouseover"):
text = i.get('onmouseover')
print(text)
以及使用 selenium 的代码:
from selenium import webdriver
from bs4 import BeautifulSoup
u = "http://188.166.44.172/match/live-stats/100941310"
driver = webdriver.Chrome(executable_path=r"C:/chromedriver.exe", options=options)
driver.get(url)
soup = BeautifulSoup(driver.page_source, 'html.parser')
for i in soup.find_all('rect'): #I also tried soup.select('*')
if i.has_attr("onmouseover"):
text = i.get('onmouseover')
print(text)
有没有办法使用 python 从这些图表中抓取数据?
【问题讨论】:
标签: python selenium web-scraping beautifulsoup