python爬取正确但不出文件_使用BeautifulSoup进行Python抓取时不显示所有行
我是美容小組的新手。我試圖從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爬取正确但不出文件_使用BeautifulSoup进行Python抓取时不显示所有行的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 电饼铛怎么做酱香饼?
- 下一篇: 希望得到学术会议的及时回复该怎么说_张烨