Skip to content

fix: WestSuffolkCouncil - send a User-Agent header#1955

Closed
InertiaUK wants to merge 5 commits into
robbrad:masterfrom
InertiaUK:fix/west-suffolk-user-agent
Closed

fix: WestSuffolkCouncil - send a User-Agent header#1955
InertiaUK wants to merge 5 commits into
robbrad:masterfrom
InertiaUK:fix/west-suffolk-user-agent

Conversation

@InertiaUK
Copy link
Copy Markdown
Contributor

What this changes

The MyWestSuffolk.aspx?action=SetAddress&UniqueId=... endpoint is served by IIS and now returns a 404 page (body 1.2KB, title "404 - File or directory not found.") to any request without a User-Agent header. Adding a realistic Chrome UA restores the full 57KB property page and the existing parser finds the bin collection panel correctly.

Change

Single one-liner: pass a headers={"User-Agent": "..."} to requests.get.

No parser changes needed — the existing panel_search helper still finds div.atPanelData under the Bin collection days <h4> once the response is the real one.

Test

Verified against UPRN 10009739960:

{
  "bins": [
    { "type": "Black bin", "collectionDate": "16/04/2026" },
    { "type": "Blue bin",  "collectionDate": "22/04/2026" },
    { "type": "Brown bin", "collectionDate": "22/04/2026" }
  ]
}

Torridge's SOAP API changed its response from explicit dates ("Mon 14 Apr")
to relative phrases ("Tomorrow then every Mon", "Today then every Tue")
with an embedded calendar table. The old regex-based parser returned empty
because it expected the old format.

The rewritten parser handles Today/Tomorrow/weekday-name phrases, falls back
to the old explicit format if it reappears, and gracefully skips "No X
collection for this address" entries.
The Wyre bin collection page now includes a 'Download calendar' box
among the .boxed divs. This box has no h3.bin-collection-tasks__heading,
which caused the scraper to crash on .text access.

Changes:
- Skip boxes missing the heading or content container
- Use regex to extract the bin name from 'Your next X collection'
- Collapse whitespace on the date text before strptime (p tags produced
  multi-whitespace runs after .text)
- Roll year forward only when the computed date is in the past, instead
  of only handling the December->January edge case
…e results

The checkyourbinday page is now:
- Gated by Cloudflare Turnstile (requires non-headless UC)
- Using WASTECOLLECTIONCALENDARV7_* element IDs (was V5)
- Rendering collection dates inline as .gi-summary-blocklist__row
  divs after address selection — no separate NEXT/submit step

Changes:
- Update all element IDs from V5 to V7
- Add Cloudflare challenge wait loop (up to 50s)
- Dismiss cookie consent before interaction (was blocking button clicks)
- Replace old table-based parsing with .gi-summary-blocklist__row scraping
- Use Select.select_by_visible_text with stale-retry instead of manual
  option.click() loop (which crashed on AJAX re-renders)
- Remove the smart_select_address helper's dead fuzzy/strict split
…anner

Stockton's AchieveForms form name changed from LOOKUPBINDATESBYADDRESSSKIPOUTOFREGION
to LOOKUPBINDATESBYADDRESSSKIPOUTOFREGIONV2, so every element ID needed
the V2 suffix added. Also added a cookie-banner dismissal step — the
banner was covering the search button and intercepting clicks.
The MyWestSuffolk.aspx IIS endpoint returns a 404 page to requests
without a User-Agent header. Adding a realistic Chrome UA restores the
full response (57KB), letting the existing parser pick up the bin
collection panel correctly.
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Apr 12, 2026

Warning

Rate limit exceeded

@InertiaUK has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 28 minutes and 32 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 28 minutes and 32 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: 7847e8ef-f130-4ec5-821a-4dae0c92a944

📥 Commits

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

📒 Files selected for processing (5)
  • uk_bin_collection/uk_bin_collection/councils/ChichesterDistrictCouncil.py
  • uk_bin_collection/uk_bin_collection/councils/StocktonOnTeesCouncil.py
  • uk_bin_collection/uk_bin_collection/councils/TorridgeDistrictCouncil.py
  • uk_bin_collection/uk_bin_collection/councils/WestSuffolkCouncil.py
  • uk_bin_collection/uk_bin_collection/councils/WyreCouncil.py
✨ 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.

@robbrad
Copy link
Copy Markdown
Owner

robbrad commented May 1, 2026

Included in May 2026 Release PR #1992. Closing.

@robbrad robbrad closed this May 1, 2026
pull Bot pushed a commit to mrw298/UKBinCollectionData that referenced this pull request May 1, 2026
Two small upstream changes have been breaking the West Suffolk scraper:

1. westsuffolk.gov.uk's IIS now 404s requests with no User-Agent. Send
   a realistic browser UA so the bin-day page returns 200 with the
   collection panel.

2. The council renamed the collection panel heading from
   "Bin collection days" to "Bin collection days current", which broke
   the exact-string `find_all(..., string="Bin collection days")` guard
   and caused an empty result. Match as a substring via a lambda so
   either label works.

Verified against live site for UPRN 10009739960 (IP28 6DR) — returns
Black / Blue / Brown collection dates.

Supersedes the earlier WestSuffolk fix in robbrad#1955 (that branch also
picked up unrelated commits from stacked council fixes and only
addressed part of the problem).
pull Bot pushed a commit to mrw298/UKBinCollectionData that referenced this pull request May 1, 2026
@robbrad robbrad mentioned this pull request May 2, 2026
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.

2 participants