我是BeautifulSoup的新手。我试图从ESPN Fantasy Basketball Standings刮掉“季节统计”表格,但并不是所有的行都被返回。经过一番研究,我认为它可能是html.parser的一个问题,所以我使用了lxml。我得到了同样的结果。如果有人能告诉我如何获得所有球队的名字,我将不胜感激。Python - 用BeautifulSoup刮没有显示所有行
我的代码:
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
你似乎是采取错误的表格。为什么不采取总排名部分? – martianwars