I would like to automatically save the data of cities from this website:
I used beautifulsoup
library to get data from a webpage
http://open.dataforcities.org/details?4[]=2016
import urllib2
from BeautifulSoup import BeautifulSoup
soup = BeautifulSoup(urllib2.urlopen('http://open.dataforcities.org/details?4[]=2016').read())
If I follow the example in Web scraping with Python I got the following error:
soup = BeautifulSoup(urllib2.urlopen('http://example.com').read())
for row in soup('table', {'class': 'metrics'})[0].tbody('tr'):
tds = row('td')
print tds[0].string, tds[1].string
IndexError Traceback (most recent call last)
<ipython-input-71-d688ff354182> in <module>()
----> 1 for row in soup('table', {'class': 'metrics'})[0].tbody('tr'):
2 tds = row('td')
3 print tds[0].string, tds[1].string
IndexError: list index out of range
[1]: http://www.dataforcities.org/
[2]: http://open.dataforcities.org/
[3]: https://i.stack.imgur.com/qfQyG.png