【发布时间】:2013-08-18 03:46:32
【问题描述】:
我想让你看看这个网站:
http://www.nhl.com/ice/teamstats.htm
现在,我的代码在这里。这只会打印出表格顶部的所有标题:
from bs4 import BeautifulSoup
from urllib.request import urlopen
url = urlopen("http://www.nhl.com/ice/teamstats.htm")
content = url.read()
soup = BeautifulSoup(content)
results = {}
for table in soup.find_all('table', class_='data stats'):
for row in table.find_all('tr'):
name = None
for cell in row.find_all('th'):
link = cell.find('a')
if link:
name = cell.a.string
print (name)
可以肯定的是,这个东西更复杂。在很多帮助和重新学习一些被遗忘的 Python 课程的帮助下,我能够在这个网站上进行团队和分数的关联:http://sports.yahoo.com/nhl/scoreboard?d=2013-04-01
但是,前一个网页(第一个)有多个与其值相关联的标题。
我只是询问其中的一些要点,以便我可以进一步完成其余的工作而不会出现问题(或者可能是一些,谁知道)。从某种意义上说,这就是我想要完成的:
Team X: GP: 30. W: 16. L: 4, etc.
谢谢!
【问题讨论】:
标签: python html python-3.x beautifulsoup