fix: update weather selectors to match DDG's actual DOM #54

Merged
steve merged 1 commits from fix/weather-selector-dom-mismatch into main 2026-02-15 23:07:10 +00:00
Collaborator

Summary

  • DuckDuckGo's weather widget uses randomized CSS module class names (e.g. wbUB0U7KMDyukXtzMd8Y) that change on every build, so all the BEM-style selectors (.module__current-temp, .forecast-day__name, etc.) return empty results
  • Replaced all class-based selectors with structural and attribute-based selectors that are resilient to class name changes:
    • Widget identified via article:has(img[src*='weatherkit'])
    • Positional selectors (div:first-child, p:first-of-type, div:nth-child(2))
    • Icon hints extracted from img[alt] attributes
    • Precipitation parsed from span > span structure
    • Humidity/Wind identified by text content matching
  • CurrentTemp now derived from first hourly entry (DDG no longer shows a standalone current temperature element)
  • HighTemp/LowTemp now derived from first daily forecast entry
  • Updated all mock tests to match the new DOM structure

Fixes #53

Test plan

  • All existing unit tests updated and passing (go test ./...)
  • Verified against live DuckDuckGo weather widget via Playwright (DOM structure confirmed)
  • Manual test with GetWeather() against live site
## Summary - DuckDuckGo's weather widget uses randomized CSS module class names (e.g. `wbUB0U7KMDyukXtzMd8Y`) that change on every build, so all the BEM-style selectors (`.module__current-temp`, `.forecast-day__name`, etc.) return empty results - Replaced all class-based selectors with structural and attribute-based selectors that are resilient to class name changes: - Widget identified via `article:has(img[src*='weatherkit'])` - Positional selectors (`div:first-child`, `p:first-of-type`, `div:nth-child(2)`) - Icon hints extracted from `img[alt]` attributes - Precipitation parsed from `span > span` structure - Humidity/Wind identified by text content matching - `CurrentTemp` now derived from first hourly entry (DDG no longer shows a standalone current temperature element) - `HighTemp`/`LowTemp` now derived from first daily forecast entry - Updated all mock tests to match the new DOM structure Fixes #53 ## Test plan - [x] All existing unit tests updated and passing (`go test ./...`) - [x] Verified against live DuckDuckGo weather widget via Playwright (DOM structure confirmed) - [ ] Manual test with `GetWeather()` against live site
Claude added 1 commit 2026-02-15 23:01:03 +00:00
fix: update weather extractor selectors to match DuckDuckGo's actual DOM
All checks were successful
CI / build (pull_request) Successful in 30s
CI / vet (pull_request) Successful in 45s
CI / test (pull_request) Successful in 48s
a32f57ec92
DuckDuckGo's weather widget uses randomized CSS module class names that
don't match the BEM-style selectors the extractor was using. Replace all
class-based selectors with structural and attribute-based selectors:

- Identify widget via article:has(img[src*='weatherkit'])
- Use positional selectors (div:first-child, p:first-of-type, etc.)
- Extract icon hints from img[alt] attributes
- Parse precipitation from span > span structure
- Derive CurrentTemp from first hourly entry (no standalone element)
- Derive HighTemp/LowTemp from first daily forecast entry
- Use text-matching for Humidity/Wind labels

Fixes #53

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
steve merged commit e8f4d64eb9 into main 2026-02-15 23:07:10 +00:00
steve deleted branch fix/weather-selector-dom-mismatch 2026-02-15 23:07:10 +00:00
Sign in to join this conversation.