From c8669002e49671a3fa18573c0ce3fa32539ed1c0 Mon Sep 17 00:00:00 2001 From: pictuga Date: Mon, 17 Jan 2022 14:22:48 +0000 Subject: [PATCH] feeds: exotic xpath in html as well --- morss/feeds.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/morss/feeds.py b/morss/feeds.py index 0389a1c..2f29d9e 100644 --- a/morss/feeds.py +++ b/morss/feeds.py @@ -488,7 +488,14 @@ class ParserHTML(ParserXML): repl = r'[@class and contains(concat(" ", normalize-space(@class), " "), " \1 ")]' rule = re.sub(pattern, repl, rule) - return self.root.xpath(rule) + match = self.root.xpath(rule) + + if isinstance(match, str): + # for some xpath rules, see XML parser + return [match,] + + else: + return match except etree.XPathEvalError: return []