Saturday, 17 August 2013

Associating multiple teams with multiple headers/values:

Associating multiple teams with multiple headers/values:

I want you to take a look at this site:
http://www.nhl.com/ice/teamstats.htm
Now, I have my code here. This only prints out all the headers on the top
of the table:
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)
Assuringly, this stuff is more complicated. I was able, with a lot of help
and relearning of some forgotten Python classes, able to do this
association of teams and scores over at this website:
http://sports.yahoo.com/nhl/scoreboard?d=2013-04-01
However, the former webpage (first one) has multiple headers associated
with their values.
What I just ask is for the gist of some of it, so that I may further
accomplish the rest without problems (or maybe a few, who knows). In a
sense, this is what I wish to accomplish:
Team X: GP: 30. W: 16. L: 4, etc.
Thanks!

No comments:

Post a Comment