【问题标题】:Webscarpping with NBA.comWebscarpping 与 NBA.com
【发布时间】:2022-12-19 19:18:22
【问题描述】:

我正在尝试从 NBA.com 进行一些网络抓取,但我正在查看的表格似乎被隐藏了。如何在请求中显示隐藏的 HTML 内容。我正在尝试出于学习目的这样做。

导入请求 从 bs4 导入 BeautifulSoup

url = 'https://www.nba.com/stats/player/203076/boxscores-traditional?Season=2022-23'
data = requests.get(url)
info = "Davis"  

with open ('{}.html'.format(info), 'w+', encoding="utf-8") as f:
    f.write(data.text)

# We read the file we created
with open ("{}.html".format(info), encoding="utf-8") as f:
    page = f.read()

# We use the BeautifulSoup library 
soup = BeautifulSoup(page,  'html.parser')
stats = soup.find_all('table', class_='Crom_table__p1iZz')

我希望看到表类 Crom_table__p1iZz 及其 tr 内容

【问题讨论】:

    标签: python html web-scraping beautifulsoup python-requests


    【解决方案1】:

    使用基于请求的抓取无法检索您正在寻找的表,至少不是您想要的方式。

    如果您能找到该站点为获取您想要的数据所做的请求,那么它可能是可能的,但是我还没有完全检查该站点,您必须自己做。

    否则,表格是使用 Javascript 加载的,您将需要使用诸如 selenium 或 chrome webdriver 之类的东西。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-07-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-03-23
      • 1970-01-01
      相关资源
      最近更新 更多