1212BASE_URL = "https://ilga.gov"
1313central = pytz .timezone ("US/Central" )
1414
15+ user_agent = os .getenv ("USER_AGENT" , "openstates" )
16+
17+ headers = {
18+ "User-Agent" : user_agent ,
19+ }
1520
1621session_details = {
1722 # TODO, fill these in once appointed
@@ -297,7 +302,7 @@ def get_bill_urls(self, chamber, session, doc_type):
297302 doc_type ,
298303 params ["SessionId" ],
299304 )
300- html = self .get (url ).text
305+ html = self .get (url , headers = headers ).text
301306 doc = lxml .html .fromstring (html )
302307 doc .make_links_absolute (url )
303308
@@ -308,7 +313,7 @@ def scrape(self, session=None, chamber=None, bill_type_abbrv=None):
308313 session_id = session
309314 # scrape a single bill for debug
310315 # yield from self.scrape_bill(
311- # 'upper', '104th', 'SB ', 'https://ilga.gov/Legislation/BillStatus?GAID=18&DocNum=2111& DocTypeID=SB &LegId=161644 &SessionID=114'
316+ # 'upper', '104th', 'HB ', 'https://ilga.gov/Legislation/BillStatus?DocNum=228& GAID=18&DocTypeID=HB &LegId=155905 &SessionID=114'
312317 # )
313318
314319 # Handle optional input parameters
@@ -365,7 +370,7 @@ def scrape(self, session=None, chamber=None, bill_type_abbrv=None):
365370 def scrape_archive_bills (self , session ):
366371 session_abr = session [0 :2 ]
367372 url = f"{ BASE_URL } /documents/legislation/legisnet{ session_abr } /{ session_abr } gatoc.html"
368- html = self .get (url ).text
373+ html = self .get (url , headers = headers ).text
369374 doc = lxml .html .fromstring (html )
370375 doc .make_links_absolute (url )
371376 bill_numbers_sections = doc .xpath ("//table//a/@href" )
@@ -388,7 +393,7 @@ def scrape_archive_bills(self, session):
388393 for bill_url in bills_urls :
389394 bill_url = clean_archivebill_url (bill_url )
390395
391- bill_html = self .get (bill_url ).text
396+ bill_html = self .get (bill_url , headers = headers ).text
392397 bill_doc = lxml .html .fromstring (bill_html )
393398 bill_doc .make_links_absolute (bill_url )
394399
@@ -414,7 +419,7 @@ def scrape_archive_bills(self, session):
414419 '//a[contains (., "Bill Summary")]/@href'
415420 )[0 ]
416421 summary_page_url = clean_archivebill_url (summary_page_url )
417- summary_page_html = self .get (summary_page_url ).text
422+ summary_page_html = self .get (summary_page_url , headers = headers ).text
418423 summary_page_doc = lxml .html .fromstring (summary_page_html )
419424 summary_page_doc .make_links_absolute (summary_page_url )
420425 else :
@@ -425,7 +430,7 @@ def scrape_archive_bills(self, session):
425430 0
426431 ]
427432 bill_url = clean_archivebill_url (bill_url )
428- bill_html = self .get (bill_url ).text
433+ bill_html = self .get (bill_url , headers = headers ).text
429434 bill_doc = lxml .html .fromstring (bill_html )
430435 bill_doc .make_links_absolute (bill_url )
431436
@@ -507,7 +512,7 @@ def scrape_archive_bills(self, session):
507512
508513 def scrape_bill (self , chamber , session , doc_type , url , bill_type = None ):
509514 try :
510- html = self .get (url ).text
515+ html = self .get (url , headers = headers ).text
511516 doc = lxml .html .fromstring (html )
512517 doc .make_links_absolute (url )
513518 except scrapelib .HTTPError as e :
@@ -606,7 +611,7 @@ def scrape_bill(self, chamber, session, doc_type, url, bill_type=None):
606611 yield from self .scrape_votes (session , bill , votes_url )
607612
608613 def scrape_documents (self , bill , version_url ):
609- html = self .get (version_url ).text
614+ html = self .get (version_url , headers = headers ).text
610615 doc = lxml .html .fromstring (html )
611616 doc .make_links_absolute (version_url )
612617 pdf_only = False
@@ -630,7 +635,7 @@ def scrape_documents(self, bill, version_url):
630635 # eed to visit the version's page, and get PDF link from there
631636 # otherwise get a faulty "latest version"/"LV" alias/duplicate
632637 url = "{}&Print=1" .format (url )
633- version_page_html = self .get (url ).text
638+ version_page_html = self .get (url , headers = headers ).text
634639 version_page_doc = lxml .html .fromstring (version_page_html )
635640 version_page_doc .make_links_absolute (url )
636641 pdf_link = version_page_doc .xpath ('//a[contains(@href, "PDF")]' )
@@ -668,7 +673,7 @@ def scrape_documents(self, bill, version_url):
668673 bill .add_document_link (name , url )
669674
670675 def scrape_votes (self , session , bill , votes_url ):
671- html = self .get (votes_url ).text
676+ html = self .get (votes_url , headers = headers ).text
672677 doc = lxml .html .fromstring (html )
673678 doc .make_links_absolute (votes_url )
674679
@@ -728,7 +733,7 @@ def scrape_votes(self, session, bill, votes_url):
728733 def fetch_pdf_lines (self , href ):
729734 # download the file
730735 try :
731- fname , resp = self .urlretrieve (href )
736+ fname , resp = self .urlretrieve (href , headers = headers )
732737 pdflines = [
733738 line .decode ("utf-8" ) for line in convert_pdf (fname , "text" ).splitlines ()
734739 ]
0 commit comments