Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PR: fix bill title #5215

Merged
merged 2 commits into from
Jan 14, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 15 additions & 6 deletions scrapers/pr/bills.py
Original file line number Diff line number Diff line change
Expand Up @@ -333,15 +333,24 @@ def scrape_bill(self, chamber, session, url):
}
html = self.s.get(url, headers=headers, verify=False).text
page = lxml.html.fromstring(html)
# search for Titulo, accent over i messes up lxml, so use 'tulo'
title = page.xpath('//main//div[contains(@class, "items-center")]/h1/text()')[
0
].strip()
if title:
bill_id = re.findall(r"[A-Z]{2}\d{4}", title)[0]

page_header_elems = page.xpath(
'//main//div[contains(@class, "items-center")]/h1/text()'
)
if len(page_header_elems) > 0:
page_header_text = page_header_elems[0].strip()
bill_id = re.findall(r"[A-Z]{2}\d{4}", page_header_text)[0]
else:
self.logger.error(f"Bill found with no bill identifier at {url}")

bill_title_elems = page.xpath(
'//span/strong[text()="Título:"]/../following-sibling::span'
)
if len(bill_title_elems) > 0:
title = bill_title_elems[0].text_content().strip()
else:
self.logger.error(f"Bill found with no title at {url}")

# PR occasionally repeats a bill at different URLs (????)
# example:
# PC0205 https://sutra.oslpr.org/medidas/152982
Expand Down
Loading