我正在尝试从中抓取一些东西这个梦幻篮球页面 http://fantasy.espn.com/basketball/league/scoreboard?leagueId=633975。我使用 Python 3.5+ 中的 BeautifulSoup 来执行此操作。
source_code = requests.get('http://fantasy.espn.com/basketball/league/standings?leagueId=633975')
plain_text = source_code.text
soup = BeautifulSoup(plain_text, 'lxml')
首先,我想将 9 个类别的标题抓取到一个 Python 列表中。所以我的清单应该是这样的categories = [FG%, FT%, 3PM, REB, AST, STL, BLK, TO, PTS]
.
我希望做的事情如下:
tableSubHead = soup.find_all('tr', class_='Table2__header-row')
tableSubHead = tableSubHead[0]
listCats = tableSubHead.find_all('th')
categories = []
for cat in listCats:
if 'title' in cat.attrs:
categories.append(cat.string)
但是,那soup.find_all('tr', class_='Table2__header-row')
返回一个空列表而不是我想要的表行元素。我怀疑这是因为当我查看页面源代码时,它与Chrome开发工具中的Inspect Element完全不同。我知道这是因为 Javascript 动态更改页面上的元素,但我不确定解决方案是什么。