DDG weather: advisory banners break current/hourly extraction #64
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Bug
When DuckDuckGo's weather widget displays a weather advisory (e.g. "Wind Advisory"), an extra
divelement is inserted in the section structure. The weather extractor uses positional CSS selectors (div:first-childanddiv:nth-child(2)) to locate the header and hourly container, so the advisory shifts these positions and causes:ul > divselector)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 headersection.SelectFirst("div:nth-child(2)")for the hourly containerWhen 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 directulchild)Fix submitted in PR #65. Replaced the positional
div:first-childanddiv:nth-child(2)selectors with structuraldiv:not(:has(ul))anddiv:has(> ul)selectors. Added a test case that verifies extraction works correctly with an advisory banner present.