【问题标题】:I'm trying to pull the table values on a website, but an empty list appears我正在尝试在网站上提取表值,但出现一个空列表
【发布时间】:2020-12-07 14:40:45
【问题描述】:

我想使用 python 从这个站点提取数据,但是当我拉出 beautifulsoup 并向库请求此表中的数据时,会创建一个空列表。你能帮我解决这个问题吗?

table in the URL

the website

url2 = "https://www.mackolik.com/mac/trabzonspor-vs-sivasspor/karsilastirma/5x6r419402ucyya2zf0ehbqxg"
r= requests.get(url2)
soup = BeautifulSoup(r.text,"html.parser")
table = soup.find_all('ul',class_ = "Opta-TabbedContent")
table
out: []

【问题讨论】:

  • 网站是否使用javascript来动态创建页面内容? requests 不做 javascript。

标签: python web-scraping beautifulsoup python-requests


【解决方案1】:

页面是动态加载的,因此 python 请求无法获取数据。你需要一个无头浏览器,比如 selenium:

 from selenium.webdriver.chrome.options import Options

 url = "https://www.mackolik.com/mac/trabzonspor-vs-sivasspor/karsilastirma/5x6r419402ucyya2zf0ehbqxg"
 options = Options()
 options.add_argument('--headless')

【讨论】:

  • 问题就这样解决了。非常感谢。
猜你喜欢
  • 2021-10-16
  • 2019-08-03
  • 1970-01-01
  • 2018-10-25
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多