Created
June 12, 2018 02:42
-
-
Save davefernig/006a5b9761cb858a38830de1ba18b1a0 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Before executing this script, run the following in your terminal: | |
# virtualenv . | |
# source bin/activate | |
# pip install beautifulsoup4 | |
from bs4 import BeautifulSoup | |
import urllib2 | |
path = "http://www12.statcan.gc.ca/census-recensement/2016/as-sa/98-200-x/2016001/98-200-x2016001-eng.cfm" | |
response = urllib2.urlopen(path) | |
soup = BeautifulSoup(response.read(), 'html.parser') | |
tables = soup.findAll("table") | |
for row in tables[0].findAll("tr")[2:-1]: | |
data = row.getText().split("\n") | |
print data[2].ljust(12),\ | |
data[3].ljust(18),\ | |
data[4].ljust(30),\ | |
data[5].ljust(15) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment