DDG weather: advisory banners break current/hourly extraction #64

Closed
opened 2026-02-20 18:22:40 +00:00 by Claude · 1 comment
Collaborator

Bug

When DuckDuckGo's weather widget displays a weather advisory (e.g. "Wind Advisory"), an extra div element is inserted in the section structure. The weather extractor uses positional CSS selectors (div:first-child and div:nth-child(2)) to locate the header and hourly container, so the advisory shifts these positions and causes:

  • Current temperature: 0 (derived from empty hourly data)
  • Hourly forecast: empty array
  • Humidity/Wind: empty strings
  • Weekly forecast: unaffected (uses structural ul > div selector)

Observed with "Erie,PA,US" query where a wind advisory is active.

Root Cause

In weather.go, extractWeather() uses:

  • section.SelectFirst("div:first-child") for the header
  • section.SelectFirst("div:nth-child(2)") for the hourly container

When an advisory div is inserted (e.g. between header and hourly), div:nth-child(2) matches the advisory instead of the hourly container.

Fix

Replace positional selectors with structural ones:

  • div:not(:has(ul)) for the header (first div without a list)
  • div:has(> ul) for the hourly container (the div with a direct ul child)
## Bug When DuckDuckGo's weather widget displays a weather advisory (e.g. "Wind Advisory"), an extra `div` element is inserted in the section structure. The weather extractor uses positional CSS selectors (`div:first-child` and `div:nth-child(2)`) to locate the header and hourly container, so the advisory shifts these positions and causes: - **Current temperature**: 0 (derived from empty hourly data) - **Hourly forecast**: empty array - **Humidity/Wind**: empty strings - **Weekly forecast**: unaffected (uses structural `ul > div` selector) Observed with "Erie,PA,US" query where a wind advisory is active. ## Root Cause In `weather.go`, `extractWeather()` uses: - `section.SelectFirst("div:first-child")` for the header - `section.SelectFirst("div:nth-child(2)")` for the hourly container When an advisory div is inserted (e.g. between header and hourly), `div:nth-child(2)` matches the advisory instead of the hourly container. ## Fix Replace positional selectors with structural ones: - `div:not(:has(ul))` for the header (first div without a list) - `div:has(> ul)` for the hourly container (the div with a direct `ul` child)
Author
Collaborator

Fix submitted in PR #65. Replaced the positional div:first-child and div:nth-child(2) selectors with structural div:not(:has(ul)) and div:has(> ul) selectors. Added a test case that verifies extraction works correctly with an advisory banner present.

Fix submitted in PR #65. Replaced the positional `div:first-child` and `div:nth-child(2)` selectors with structural `div:not(:has(ul))` and `div:has(> ul)` selectors. Added a test case that verifies extraction works correctly with an advisory banner present.
steve closed this issue 2026-02-20 18:23:54 +00:00
Sign in to join this conversation.