]> git.mxchange.org Git - fba.git/commitdiff
Continued:
authorRoland Häder <roland@mxchange.org>
Sun, 31 Mar 2024 05:01:10 +0000 (07:01 +0200)
committerRoland Häder <roland@mxchange.org>
Sun, 31 Mar 2024 05:01:10 +0000 (07:01 +0200)
- handled ParserRejectedMarkup properly

fba/http/csrf.py

index a66fa02fb1ea4c966a3dfb277963dda5c40c08bb..0e9a3a87bae74e0b3d05a7d6d1160c94fe61a193 100644 (file)
@@ -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: