I’m trying to scrape weather data from a (US) National Weather Service page: Weather Story. It’s a dynamic page that updates usually once per day, and when it updates it can have 1-4 different info tabs; today there are two tabs. I’d like to collect the text blurbs that appear on each tab.
What I’m trying to do works simply and perfectly using BeautifulSoup interactively:
>>> import requests
>>> from bs4 import BeautifulSoup
>>> response = requests.get("https://www.weather.gov/iln/weatherstory")
>>> soup = BeautifulSoup(response.content, "html.parser")
>>> print(soup.select("div.graphicast > div.description"))
[<div class="description">
Showers and thunderstorms this afternoon may produce strong to damaging wind gusts as well as locally heavy rain. Additional storms overnight, mainly after midnight, will pose another heavy rain threat.
</div>, <div class="description">
Warm and humid conditions will persist through the weekend with several chances of showers and storms. After a cold front moves through, temperatures will be cooler starting Monday. However, periods of showers and embedded thunderstorms will continue into Wednesday.
</div>]
>>> print(soup.select("div.graphicast > div.description")[0])
<div class="description">
Showers and thunderstorms this afternoon may produce strong to damaging wind gusts as well as locally heavy rain. Additional storms overnight, mainly after midnight, will pose another heavy rain threat.
</div>
>>> print(soup.select("div.graphicast > div.description")[1])
<div class="description">
Warm and humid conditions will persist through the weekend with several chances of showers and storms. After a cold front moves through, temperatures will be cooler starting Monday. However, periods of showers and embedded thunderstorms will continue into Wednesday.
</div>
The selector grabs exactly what I want from the page, and I can break out the two results via index 0 and index 1.
When I use the Scrape integration in HA, and use the same resource, same selector, and two sensors using index 0 and index 1, I get:
Index 0: “Showers and thunderstorms this afternoon may produce strong to damaging wind gusts as well as locally heavy rain. Additional storms overnight, mainly after midnight, will pose another heavy rain threat.” This is as expected.
Index 1: “unknown” Not as expected – see above for interactive results.
I have debug logging turned on for this integration but no messages appear in the log. What’s happening with index 1?
Any ideas?
