From d57f688583d6ef97e74878626589c38ef5ccb58a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gina=20H=C3=A4u=C3=9Fge?= Date: Sun, 19 Apr 2020 15:27:36 +0200 Subject: [PATCH] Improve parsing to work around HTML quirks in source --- custom_components/coronavirus_hessen/__init__.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/custom_components/coronavirus_hessen/__init__.py b/custom_components/coronavirus_hessen/__init__.py index dc87831..b92d43e 100644 --- a/custom_components/coronavirus_hessen/__init__.py +++ b/custom_components/coronavirus_hessen/__init__.py @@ -73,16 +73,16 @@ async def async_get_data(): result = dict() rows = data.select("article table:first-of-type tr") - for row in rows[1:]: + for row in rows[2:]: line = row.select("td") if len(line) != 7: continue try: - county = line[0].text.strip() - cases = parse_num(line[1].text.strip()) - hospitalized = parse_num(line[2].text.strip()) - deaths = parse_num(line[3].text.strip()) + county = line[0].get_text(" ", strip=True) + cases = parse_num(line[1].get_text(" ", strip=True)) + hospitalized = parse_num(line[2].get_text(" ", strip=True)) + deaths = parse_num(line[3].get_text(" ", strip=True)) except: _LOGGER.exception("Error processing line {}, skipping".format(line)) continue