From cac12e2c7aeaedc72211257bc747d83dc7e74b1f Mon Sep 17 00:00:00 2001 From: WEN Hao Date: Sun, 25 Aug 2024 01:02:02 +0800 Subject: [PATCH] enhance the text format lookup results --- bib_lookup/bib_lookup.py | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/bib_lookup/bib_lookup.py b/bib_lookup/bib_lookup.py index 120165e..c295929 100644 --- a/bib_lookup/bib_lookup.py +++ b/bib_lookup/bib_lookup.py @@ -465,14 +465,17 @@ def __call__( res = self._handle_network_error(res) - if res not in self.lookup_errors and format in ["bibtex", "bibentry"]: - try: - res = self._to_bib_item(res, idtf, align, ignore_fields, label) - self.__cached_lookup_results[identifier] = res - if len(self.__cached_lookup_results) > self.__cache_limit: - self.__cached_lookup_results.popitem(last=False) - except Exception: - res = self.default_err + if res not in self.lookup_errors: + if format in ["bibtex", "bibentry"]: + try: + res = self._to_bib_item(res, idtf, align, ignore_fields, label) + self.__cached_lookup_results[identifier] = res + if len(self.__cached_lookup_results) > self.__cache_limit: + self.__cached_lookup_results.popitem(last=False) + except Exception: + res = self.default_err + elif format == "text": + res = BeautifulSoup(res, "html.parser").get_text() if self.verbose >= 1: if res in self.lookup_errors: