Skip to content

Instantly share code, notes, and snippets.

@martinth
Created July 29, 2011 16:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save martinth/1114198 to your computer and use it in GitHub Desktop.
Save martinth/1114198 to your computer and use it in GitHub Desktop.
from urllib2 import urlopen
from BeautifulSoup import BeautifulSoup
data = urlopen('''http://www.hydro.eaufrance.fr/stations/O7502510&procedure=tousmois''').read()
soup = BeautifulSoup(data)
table = soup.find('table', {'summary': "valeurs mensuelles et annuelles"})
for tr in table.findAll('tr'):
line = []
for td in tr.findAll('td'):
try:
line.append(td.find('input', {'name':'value'})['value'])
except TypeError:
line.append(td.text)
print ','.join(line)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment