Skip to content

Instantly share code, notes, and snippets.

@davefernig
Created June 12, 2018 02:42
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save davefernig/006a5b9761cb858a38830de1ba18b1a0 to your computer and use it in GitHub Desktop.
Save davefernig/006a5b9761cb858a38830de1ba18b1a0 to your computer and use it in GitHub Desktop.
# 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