Created
March 22, 2009 21:57
-
-
Save jroo/83306 to your computer and use it in GitHub Desktop.
returns list of GAO reports for past year
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
import datetime, time | |
import urllib2 | |
from BeautifulSoup import BeautifulSoup | |
#returns list of GAO reports for past year | |
def grab_gao(): | |
doc_type = "GAO" | |
page = urllib2.urlopen("http://gao.gov/docsearch/pastyear.html") | |
soup = BeautifulSoup(page) | |
report_list = [] | |
for report in soup('dl'): | |
title = report('dt')[0].renderContents().replace('<strong>', '').replace('</strong>', '') | |
category = report('dt')[0]('strong')[0].renderContents() | |
original_url = report('dd')[0].find('a')['href'] | |
gov_id = report('dd')[0].find('a').string.strip() | |
date_str = report('dd')[0].find('a').nextSibling.lstrip(', ') | |
release_date = time.strftime('%Y-%m-%d', time.strptime(date_str, '%B %d, %Y')) | |
gao_report = {'doc_type':doc_type, 'gov_id':gov_id, 'release_date':release_date, 'title':title, | |
'category':category, 'original_url':original_url} | |
report_list.append(gao_report) | |
return report_list |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment