【发布时间】:2016-12-17 19:07:39
【问题描述】:
我是 BeautifulSoup 的新手。我正在尝试从ESPN Fantasy Basketball Standings 中抓取“Season Stats”表,但并非所有行都返回。经过一番研究,我认为可能是html.parser的问题,所以我使用了lxml。我得到了同样的结果。如果有人能告诉我如何获得所有团队名称,我将不胜感激。
我的代码:
from bs4 import BeautifulSoup
from urllib.request import urlopen
soup = BeautifulSoup(urlopen("http://games.espn.com/fba/standings?leagueId=20960&seasonId=2017"),'html.parser')
tableStats = soup.find("table", {"class" : "tableBody"})
for row in tableStats.findAll('tr')[2:]:
col = row.findAll('td')
try:
name = col[0].a.string.strip()
print(name)
except Exception as e:
print(str(e))
输出(如您所见,只显示了几个团队名称):
Le Tuc Grizzlies
Peyton Ravens
Heaven Vultures
Versailles Golden Bears
Baltimore Corto's
La Murette Scavengers
XO Gayfishes
【问题讨论】:
-
您似乎走错了桌子。为什么不参加总排名部分?
标签: python web-scraping beautifulsoup