Created
June 12, 2018 02:42
-
-
Save davefernig/006a5b9761cb858a38830de1ba18b1a0 to your computer and use it in GitHub Desktop.
Revisions
-
davefernig created this gist
Jun 12, 2018 .There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,21 @@ # 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)