python - I do not quite understand how to parse the Yahoo NHL Page -


here code far:

from bs4 import beautifulsoup urllib.request import urlopen  url = urlopen("http://sports.yahoo.com/nhl/scoreboard?d=2013-04-01")  content = url.read()  soup = beautifulsoup(content)  print (soup.prettify)  table = soup.find('table') rows = table.findall('tr')  tr in rows:     cols = tr.findall('td')     td in cols:         text = td.findall('yspscores')         yspscores in td:             print (yspscores) 

the problem i've been having html yahoo page has table data in context: <td class="yspscores">

i not quite understand how reference in code. goal print out scores , name of teams score corresponds to.

you grabbed first table, there more 1 table on page. in fact, there 46 tables.

you want find tables scores class:

for table in soup.find_all('table', class_='scores'):     row in table.find_all('tr'):         cell in row.find_all('td', class_='yspscores'):             print(cell.text) 

note searching specific class done class_ keyword argument.


Comments

Popular posts from this blog

ios - UICollectionView Self Sizing Cells with Auto Layout -

node.js - ldapjs - write after end error -

DOM Manipulation in Wordpress (and elsewhere) using php -