【发布时间】:2019-08-07 10:45:33
【问题描述】:
我一直在尝试从here 刮一张桌子,但没有成功。我试图抓取的表格标题为“每场比赛的球队统计数据”。我有信心,一旦我能够抓取该表的一个元素,我就可以从列表中遍历我想要的列,并最终得到一个 pandas 数据框。
到目前为止,这是我的代码:
from bs4 import BeautifulSoup
import requests
# url that we are scraping
r = requests.get('https://www.basketball-reference.com/leagues/NBA_2019.html')
# Lets look at what the request content looks like
print(r.content)
# use Beautifulsoup on content from request
c = r.content
soup = BeautifulSoup(c)
print(soup)
# using prettify() in Beautiful soup indents HTML like it should be in the web page
# This can make reading the HTML a little be easier
print(soup.prettify())
# get elements within the 'main-content' tag
team_per_game = soup.find(id="all_team-stats-per_game")
print(team_per_game)
任何帮助将不胜感激。
【问题讨论】:
-
该页面作弊,表格的 HTML 源存储在 HTML cmets 中,Javascript then extracts 并返回到 HTML...
-
这是防止刮擦的预防方法吗?
-
更可能的原因是阻止表格显示在 Google 结果页面中。
标签: python web-scraping beautifulsoup