fix: use structural selectors for DDG weather advisory handling #65

Merged
steve merged 1 commits from fix/weather-advisory-selectors into main 2026-02-20 18:23:54 +00:00
Collaborator

Summary

  • Replace positional CSS selectors (div:first-child, div:nth-child(2)) with structural ones (div:not(:has(ul)), div:has(> ul)) so the weather extractor works when DuckDuckGo inserts advisory banners (e.g. wind advisory for Erie, PA)
  • Add TestExtractWeather_WithAdvisory test case verifying extraction succeeds with an advisory div present

Root Cause

The hourly container was located with div:nth-child(2), which breaks when an advisory banner inserts an extra div before it. The weekly forecast was unaffected because it already used the structural selector ul > div.

Test Plan

  • All existing weather tests pass
  • New TestExtractWeather_WithAdvisory test passes
  • Full go test ./... passes

Fixes #64

## Summary - Replace positional CSS selectors (`div:first-child`, `div:nth-child(2)`) with structural ones (`div:not(:has(ul))`, `div:has(> ul)`) so the weather extractor works when DuckDuckGo inserts advisory banners (e.g. wind advisory for Erie, PA) - Add `TestExtractWeather_WithAdvisory` test case verifying extraction succeeds with an advisory div present ## Root Cause The hourly container was located with `div:nth-child(2)`, which breaks when an advisory banner inserts an extra `div` before it. The weekly forecast was unaffected because it already used the structural selector `ul > div`. ## Test Plan - [x] All existing weather tests pass - [x] New `TestExtractWeather_WithAdvisory` test passes - [x] Full `go test ./...` passes Fixes #64
Claude added 1 commit 2026-02-20 18:23:05 +00:00
fix: use structural selectors for DDG weather to handle advisory banners
All checks were successful
CI / build (pull_request) Successful in 1m11s
CI / vet (pull_request) Successful in 1m12s
CI / test (pull_request) Successful in 1m17s
8c2848246b
The weather extractor used positional CSS selectors (div:first-child,
div:nth-child(2)) to locate the header and hourly container within the
widget section. When DuckDuckGo inserts advisory banners (e.g. wind
advisory), the extra div shifts positions and breaks extraction of
current temp, hourly data, humidity, and wind.

Replace with structural selectors:
- div:not(:has(ul)) for the header (first div without a list)
- div:has(> ul) for the hourly container (div with direct ul child)

These match elements by their content structure rather than position,
so advisory banners no longer break extraction.

Fixes #64

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
steve merged commit 710d75259e into main 2026-02-20 18:23:54 +00:00
steve deleted branch fix/weather-advisory-selectors 2026-02-20 18:23:54 +00:00
Sign in to join this conversation.