Scrape HTML attributes that are not key/val pairs (#58247)

This commit is contained in:
MizterB
2022-01-21 05:17:48 -05:00
committed by GitHub
parent 5954ca2b1f
commit 604a900658

View File

@@ -160,6 +160,7 @@ class ScrapeSensor(SensorEntity):
raw_data = BeautifulSoup(self.rest.data, "html.parser")
_LOGGER.debug(raw_data)
try:
if self._attr is not None:
value = raw_data.select(self._select)[self._index][self._attr]
else:
@@ -168,6 +169,14 @@ class ScrapeSensor(SensorEntity):
value = tag.string
else:
value = tag.text
except IndexError:
_LOGGER.warning("Index '%s' not found in %s", self._attr, self.entity_id)
value = None
except KeyError:
_LOGGER.warning(
"Attribute '%s' not found in %s", self._attr, self.entity_id
)
value = None
_LOGGER.debug(value)
return value