From daca3e837ca3ddd8e9809189a1e93b759aa774b0 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Roland=20H=C3=A4der?= Date: Wed, 15 Jan 2025 03:12:11 +0100 Subject: [PATCH] Continued: - need to skip invalid table headers, they should be introduced with and then each column but some website may use instead of - strip (trim) strings --- fba/networks/friendica.py | 4 ++++ fba/networks/pleroma.py | 8 ++++++-- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/fba/networks/friendica.py b/fba/networks/friendica.py index fcf9e5c..4d252e1 100644 --- a/fba/networks/friendica.py +++ b/fba/networks/friendica.py @@ -87,6 +87,10 @@ def fetch_blocks(domain: str) -> list: tds = line.find_all("td") logger.debug("tds[%s]()=%d", type(tds), len(tds)) + if len(tds) == 0: + logger.warning("No 'td' tag found in line[]='%s' - SKIPPED!", type(line)) + continue + blocked = tds[0].text.strip() reason = tds[1].text.strip() diff --git a/fba/networks/pleroma.py b/fba/networks/pleroma.py index 1d98332..3cfa9a6 100644 --- a/fba/networks/pleroma.py +++ b/fba/networks/pleroma.py @@ -376,8 +376,12 @@ def fetch_blocks_from_about(domain: str) -> dict: tds = line.find_all("td") logger.debug("tds[%s]()=%d", type(tds), len(tds)) - blocked = tds[0].text - reason = tds[1].text + if len(tds) == 0: + logger.warning("No 'td' tag found in line[]='%s' - SKIPPED!", type(line)) + continue + + blocked = tds[0].text.strip() + reason = tds[1].text.strip() logger.debug("blocked='%s',reason='%s' - BEFORE!", blocked, reason) blocked = tidyup.domain(blocked) if blocked != "" else None -- 2.39.5