mirror of
https://github.com/home-assistant/core.git
synced 2025-07-23 13:17:32 +00:00
Scrape HTML attributes that are not key/val pairs (#58247)
This commit is contained in:
parent
5954ca2b1f
commit
604a900658
@ -160,6 +160,7 @@ class ScrapeSensor(SensorEntity):
|
|||||||
raw_data = BeautifulSoup(self.rest.data, "html.parser")
|
raw_data = BeautifulSoup(self.rest.data, "html.parser")
|
||||||
_LOGGER.debug(raw_data)
|
_LOGGER.debug(raw_data)
|
||||||
|
|
||||||
|
try:
|
||||||
if self._attr is not None:
|
if self._attr is not None:
|
||||||
value = raw_data.select(self._select)[self._index][self._attr]
|
value = raw_data.select(self._select)[self._index][self._attr]
|
||||||
else:
|
else:
|
||||||
@ -168,6 +169,14 @@ class ScrapeSensor(SensorEntity):
|
|||||||
value = tag.string
|
value = tag.string
|
||||||
else:
|
else:
|
||||||
value = tag.text
|
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)
|
_LOGGER.debug(value)
|
||||||
return value
|
return value
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user