Skip to content

Commit

Permalink
Unescape HTML Entities Cloudflare introduced on the challenge request.
Browse files Browse the repository at this point in the history
  • Loading branch information
VeNoMouS committed Feb 10, 2020
1 parent 7986476 commit fc9bf19
Showing 1 changed file with 29 additions and 4 deletions.
33 changes: 29 additions & 4 deletions cloudscraper/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,14 @@
except ImportError:
import copy_reg as copyreg

try:
from HTMLParser import HTMLParser
except ImportError:
if sys.version_info >= (3, 4):
import html
else:
from html.parser import HTMLParser

from copy import deepcopy
from time import sleep
from collections import OrderedDict
Expand Down Expand Up @@ -286,12 +294,29 @@ def is_Challenge_Request(self, resp):

@staticmethod
def IUAM_Challenge_Response(body, url, interpreter):

# ------------------------------------------------------------------------------- #

def unescape(html_text):
if sys.version_info >= (3, 0):
if sys.version_info >= (3, 4):
return html.unescape(html_text)

return HTMLParser().unescape(html_text)

return HTMLParser().unescape(html_text)

# ------------------------------------------------------------------------------- #

try:
challengeUUID = re.search(
r'id="challenge-form" action="(?P<challengeUUID>\S+)"',
body, re.M | re.DOTALL
).groupdict().get('challengeUUID', '')
challengeUUID = unescape(
re.search(
r'id="challenge-form" action="(?P<challengeUUID>\S+)"',
body, re.M | re.DOTALL
).groupdict().get('challengeUUID', '')
)
payload = OrderedDict(re.findall(r'name="(r|jschl_vc|pass)"\svalue="(.*?)"', body))

except AttributeError:
sys.tracebacklimit = 0
raise RuntimeError(
Expand Down

0 comments on commit fc9bf19

Please sign in to comment.