Parse json string in non-strict mode

This commit is contained in:
C5H12O5
2023-08-12 12:44:32 +08:00
parent 9c6df76459
commit 3e1c9a0efc
2 changed files with 3 additions and 3 deletions

View File

@ -83,8 +83,8 @@ def _start(flow: "ScrapeFlow", limit: int):
_results.append(next(result_gen))
except StopIteration:
break
except ScrapeError as e:
_logger.error("Error while scraping: %s", e)
except ScrapeError:
_logger.error("Failed to scrape from %s", flow.site, exc_info=True)
class ScrapeFlow:

View File

@ -33,7 +33,7 @@ def str_to_etree(string: str) -> Optional[ElementTree.Element]:
"""Convert a string to an ElementTree."""
string = string.strip()
if string.startswith("{") or string.startswith("["):
return json_to_etree(json.loads(string))
return json_to_etree(json.loads(string, strict=False))
elif string.startswith("<"):
return html_to_etree(string)
return None