From: Roland Häder Date: Sun, 31 Mar 2024 05:01:10 +0000 (+0200) Subject: Continued: X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=a05a9a2d8a1476e71629d681c6ba1ab707873e52;p=fba.git Continued: - handled ParserRejectedMarkup properly --- diff --git a/fba/http/csrf.py b/fba/http/csrf.py index a66fa02..0e9a3a8 100644 --- a/fba/http/csrf.py +++ b/fba/http/csrf.py @@ -59,13 +59,20 @@ def determine(domain: str, headers: dict) -> dict: logger.debug("Parsing response.text()=%d Bytes ...", len(response.text)) cookies.store(domain, response.cookies.get_dict()) + # Init tag + tag = None + # Parse text - meta = bs4.BeautifulSoup( - response.text, - "html.parser" - ) - logger.debug("meta[]='%s'", type(meta)) - tag = meta.find("meta", attrs={"name": "csrf-token"}) + try: + meta = bs4.BeautifulSoup( + response.text, + "html.parser" + ) + + logger.debug("meta[]='%s'", type(meta)) + tag = meta.find("meta", attrs={"name": "csrf-token"}) + except bs4.builder.ParserRejectedMarkup: + logger.warning("domain='%s' has returned invalid HTML markup", domain) logger.debug("tag[%s]='%s'", type(tag), tag) if tag is not None: