Skip to content

fix: BexleyCouncil - replace Selenium with requests (WasteWorks HTML)#1937

Open
InertiaUK wants to merge 2 commits intorobbrad:masterfrom
InertiaUK:fix/BexleyCouncil
Open

fix: BexleyCouncil - replace Selenium with requests (WasteWorks HTML)#1937
InertiaUK wants to merge 2 commits intorobbrad:masterfrom
InertiaUK:fix/BexleyCouncil

Conversation

@InertiaUK
Copy link
Copy Markdown

@InertiaUK InertiaUK commented Apr 9, 2026

Bexley migrated to WasteWorks, and the new results page is plain static HTML — no JavaScript needed to render the bin schedule.

Dropped the Selenium flow entirely and switched to a requests + BeautifulSoup scrape against the WasteWorks results URL. Much faster and no webdriver dependency for this council.

Tested with a real UPRN in Bexley.

Summary by CodeRabbit

  • Bug Fixes
    • Improved reliability of Bexley Council bin collection schedule retrieval with automatic retry logic
    • Enhanced performance and speed of bin collection data updates

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Apr 9, 2026

Warning

Rate limit exceeded

@InertiaUK has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 25 minutes and 11 seconds before requesting another review.

Your organization is not enrolled in usage-based pricing. Contact your admin to enable usage-based pricing to continue reviews beyond the rate limit, or try again in 25 minutes and 11 seconds.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 639419ed-b6cf-45d2-bcc2-145bfe81c207

📥 Commits

Reviewing files that changed from the base of the PR and between 0be02ac and a97dd39.

📒 Files selected for processing (1)
  • uk_bin_collection/uk_bin_collection/councils/BexleyCouncil.py
📝 Walkthrough

Walkthrough

Replaced Selenium-based web scraping with direct requests.get HTTP fetching and BeautifulSoup parsing in the Bexley Council scraper. Added retry logic to re-fetch when expected HTML markers are absent. Updated extraction logic to derive bin types from h3.waste-service-name elements and parse collection dates from dl.govuk-summary-list__row structures using date format detection.

Changes

Cohort / File(s) Summary
Bexley Council Scraper Refactor
uk_bin_collection/uk_bin_collection/councils/BexleyCouncil.py
Replaced Selenium webdriver and DOM wait logic with requests.get + BeautifulSoup parsing. Added 3-attempt retry loop when "waste-service-name" marker is absent. Refactored bin type and collection date extraction to iterate over div.waste-service-grid containers and parse dates from dl.govuk-summary-list__row entries with support for multiple date formats. Removed Selenium-specific driver cleanup and early-return failure paths.

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

Possibly related PRs

Suggested reviewers

  • dp247

Poem

🐰 Hop, hop, hooray! The browser beasts are gone,
No more Selenium waits to dawn,
Direct requests now fetch the way,
BeautifulSoup makes parsing play,
Bins collected, dates divine,
Our scraper's code is lean and fine! ✨

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title directly and accurately summarizes the main change: replacing Selenium with requests for BexleyCouncil's WasteWorks HTML scraping, which is the primary objective of the PR.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 3

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@uk_bin_collection/uk_bin_collection/councils/BexleyCouncil.py`:
- Around line 27-35: The retry loop that fetches the page retries up to 3 times
but then proceeds to parse whatever response was last received, which can hide
transient failures; after the for-attempt loop (the block that checks for
"waste-service-name" in response.text), detect if the marker was never found and
raise a clear exception (e.g., RuntimeError or ValueError) including the
URL/page and last response.status_code/text snippet so callers of BexleyCouncil
parsing know the fetch failed instead of silently returning an empty bins list;
ensure this change is made where response and soup are set so downstream code
cannot continue on an unexpected page format.
- Around line 19-21: The code silently allows kwargs.get("uprn") to be None
which yields a request to "/waste/None"; update the logic in BexleyCouncil
(where user_uprn is obtained and page is built) to explicitly validate the UPRN:
either use kwargs["uprn"] or check if user_uprn is truthy and raise a clear
exception (e.g., ValueError with a message like "Missing required 'uprn'")
before constructing page = f"https://waste.bexley.gov.uk/waste/{user_uprn}", so
callers fail fast on bad input.
- Around line 41-82: The parser currently swallows many failures; instead make
each unexpected/malformed case raise a clear exception so callers can detect
markup changes: when h3 is missing in the grid raise a ValueError (include grid
context), when summary_list is missing raise a ValueError, when no "Next
collection" dt is found for a service raise a ValueError naming the
service/bin_type (use service_name_elem or bin_type), when dd is missing raise a
ValueError, and when date parsing fails (in
remove_ordinal_indicator_from_date_string / datetime.strptime) re-raise a
ValueError with a message containing bin_type and the raw next_collection string
rather than printing; update the loop in BexleyCouncil.py that handles grids,
h3, summary_list, rows, dt, dd, next_collection and the date parsing to raise
these exceptions with contextual text.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 509146d0-72a5-4b8f-b008-196ee8d156c8

📥 Commits

Reviewing files that changed from the base of the PR and between 60bd3cc and 0be02ac.

📒 Files selected for processing (1)
  • uk_bin_collection/uk_bin_collection/councils/BexleyCouncil.py

@InertiaUK
Copy link
Copy Markdown
Author

Fair points — pushed fixes for all three:

  1. UPRN validation: added check_uprn(user_uprn) so a missing UPRN raises immediately instead of requesting /waste/None.
  2. Retry exhaustion: the loop now tracks whether the expected marker was found and raises ValueError after 3 failed attempts instead of parsing a bad page.
  3. Empty result: added a check at the end that raises if no bins were parsed — catches silent markup changes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant