Skip to content

Instantly share code, notes, and snippets.

@higs4281
Created August 23, 2014 01:27
Show Gist options
  • Save higs4281/bf6d309ff84da316e714 to your computer and use it in GitHub Desktop.
Save higs4281/bf6d309ff84da316e714 to your computer and use it in GitHub Desktop.
extracting csv
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