Created
August 23, 2014 01:27
-
-
Save higs4281/bf6d309ff84da316e714 to your computer and use it in GitHub Desktop.
extracting csv
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 characters
from bs4 import BeautifulSoup as bs | |
from csvkit import CSVKitWriter as ckw | |
with open('enrollment.html', 'r') as f: | |
soup = bs(f.read()) | |
rows = soup.find('table').findAll('tr') | |
header = [td.text for td in rows[0].findAll('td')] | |
with open('enrollment.csv', 'w') as f: | |
writer = ckw(f) | |
writer.writerow(header) | |
for row in rows[1:]: | |
writer.writerow(cell.text for cell in row.findAll('td')) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment