aggiornato cloudscraper (fix piratestreaming)
This commit is contained in:
@@ -28,6 +28,7 @@ from .exceptions import (
|
|||||||
CloudflareLoopProtection,
|
CloudflareLoopProtection,
|
||||||
CloudflareCode1020,
|
CloudflareCode1020,
|
||||||
CloudflareIUAMError,
|
CloudflareIUAMError,
|
||||||
|
CloudflareChallengeError,
|
||||||
CloudflareReCaptchaError,
|
CloudflareReCaptchaError,
|
||||||
CloudflareReCaptchaProvider
|
CloudflareReCaptchaProvider
|
||||||
)
|
)
|
||||||
@@ -54,7 +55,7 @@ except ImportError:
|
|||||||
|
|
||||||
# ------------------------------------------------------------------------------- #
|
# ------------------------------------------------------------------------------- #
|
||||||
|
|
||||||
__version__ = '1.2.34'
|
__version__ = '1.2.35'
|
||||||
|
|
||||||
# ------------------------------------------------------------------------------- #
|
# ------------------------------------------------------------------------------- #
|
||||||
|
|
||||||
@@ -265,6 +266,27 @@ class CloudScraper(Session):
|
|||||||
|
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
# ------------------------------------------------------------------------------- #
|
||||||
|
# check if the response contains new Cloudflare challenge
|
||||||
|
# ------------------------------------------------------------------------------- #
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def is_New_IUAM_Challenge(resp):
|
||||||
|
try:
|
||||||
|
return (
|
||||||
|
resp.headers.get('Server', '').startswith('cloudflare')
|
||||||
|
and resp.status_code in [429, 503]
|
||||||
|
and re.search(
|
||||||
|
r'cpo.src="/cdn-cgi/challenge-platform/orchestrate/jsch/v1"',
|
||||||
|
resp.text,
|
||||||
|
re.M | re.DOTALL
|
||||||
|
)
|
||||||
|
)
|
||||||
|
except AttributeError:
|
||||||
|
pass
|
||||||
|
|
||||||
|
return False
|
||||||
|
|
||||||
# ------------------------------------------------------------------------------- #
|
# ------------------------------------------------------------------------------- #
|
||||||
# check if the response contains a valid Cloudflare reCaptcha challenge
|
# check if the response contains a valid Cloudflare reCaptcha challenge
|
||||||
# ------------------------------------------------------------------------------- #
|
# ------------------------------------------------------------------------------- #
|
||||||
@@ -318,6 +340,12 @@ class CloudScraper(Session):
|
|||||||
'Cloudflare has blocked this request (Code 1020 Detected).'
|
'Cloudflare has blocked this request (Code 1020 Detected).'
|
||||||
)
|
)
|
||||||
|
|
||||||
|
if self.is_New_IUAM_Challenge(resp):
|
||||||
|
self.simpleException(
|
||||||
|
CloudflareChallengeError,
|
||||||
|
'Detected the new Cloudflare challenge.'
|
||||||
|
)
|
||||||
|
|
||||||
if self.is_reCaptcha_Challenge(resp) or self.is_IUAM_Challenge(resp):
|
if self.is_reCaptcha_Challenge(resp) or self.is_IUAM_Challenge(resp):
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|||||||
@@ -36,6 +36,12 @@ class CloudflareIUAMError(CloudflareException):
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
|
|
||||||
|
class CloudflareChallengeError(CloudflareException):
|
||||||
|
"""
|
||||||
|
Raise an error when detected new Cloudflare challenge
|
||||||
|
"""
|
||||||
|
|
||||||
|
|
||||||
class CloudflareSolveError(CloudflareException):
|
class CloudflareSolveError(CloudflareException):
|
||||||
"""
|
"""
|
||||||
Raise an error when issue with solving Cloudflare challenge
|
Raise an error when issue with solving Cloudflare challenge
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ from __future__ import absolute_import
|
|||||||
import re
|
import re
|
||||||
import operator as op
|
import operator as op
|
||||||
|
|
||||||
|
from ..exceptions import CloudflareSolveError
|
||||||
from . import JavaScriptInterpreter
|
from . import JavaScriptInterpreter
|
||||||
|
|
||||||
# ------------------------------------------------------------------------------- #
|
# ------------------------------------------------------------------------------- #
|
||||||
@@ -62,13 +63,16 @@ class ChallengeInterpreter(JavaScriptInterpreter):
|
|||||||
def challengeSolve(body, domain):
|
def challengeSolve(body, domain):
|
||||||
jschl_answer = 0
|
jschl_answer = 0
|
||||||
|
|
||||||
jsfuckChallenge = re.search(
|
try:
|
||||||
r"setTimeout\(function\(\){\s+var.*?f,\s*(?P<variable>\w+).*?:(?P<init>\S+)};"
|
jsfuckChallenge = re.search(
|
||||||
r".*?\('challenge-form'\);\s+;(?P<challenge>.*?a\.value)"
|
r"setTimeout\(function\(\){\s+var.*?f,\s*(?P<variable>\w+).*?:(?P<init>\S+)};"
|
||||||
r"(?:.*id=\"cf-dn-.*?>(?P<k>\S+)<)?",
|
r".*?\('challenge-form'\);\s+;(?P<challenge>.*?a\.value)"
|
||||||
body,
|
r"(?:.*id=\"cf-dn-.*?>(?P<k>\S+)<)?",
|
||||||
re.DOTALL | re.MULTILINE
|
body,
|
||||||
).groupdict()
|
re.DOTALL | re.MULTILINE
|
||||||
|
).groupdict()
|
||||||
|
except AttributeError:
|
||||||
|
raise CloudflareSolveError('There was an issue extracting the Cloudflare challenge.')
|
||||||
|
|
||||||
jsfuckChallenge['challenge'] = re.finditer(
|
jsfuckChallenge['challenge'] = re.finditer(
|
||||||
r'{}.*?([+\-*/])=(.*?);(?=a\.value|{})'.format(
|
r'{}.*?([+\-*/])=(.*?);(?=a\.value|{})'.format(
|
||||||
|
|||||||
@@ -12,7 +12,6 @@ except ImportError:
|
|||||||
)
|
)
|
||||||
|
|
||||||
from ..exceptions import (
|
from ..exceptions import (
|
||||||
reCaptchaException,
|
|
||||||
reCaptchaServiceUnavailable,
|
reCaptchaServiceUnavailable,
|
||||||
reCaptchaAPIError,
|
reCaptchaAPIError,
|
||||||
reCaptchaTimeout,
|
reCaptchaTimeout,
|
||||||
@@ -144,7 +143,7 @@ class captchaSolver(reCaptcha):
|
|||||||
|
|
||||||
# ------------------------------------------------------------------------------- #
|
# ------------------------------------------------------------------------------- #
|
||||||
|
|
||||||
def requestSolve(self, url, siteKey):
|
def requestSolve(self, captchaType, url, siteKey):
|
||||||
def _checkRequest(response):
|
def _checkRequest(response):
|
||||||
if response.ok and response.text.startswith('{') and response.json().get('captchaid'):
|
if response.ok and response.text.startswith('{') and response.json().get('captchaid'):
|
||||||
return response
|
return response
|
||||||
@@ -153,6 +152,11 @@ class captchaSolver(reCaptcha):
|
|||||||
|
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
captchaMap = {
|
||||||
|
'reCaptcha': 'recaptchav2',
|
||||||
|
'hCaptcha': 'hcaptcha'
|
||||||
|
}
|
||||||
|
|
||||||
response = polling.poll(
|
response = polling.poll(
|
||||||
lambda: self.session.post(
|
lambda: self.session.post(
|
||||||
self.host,
|
self.host,
|
||||||
@@ -161,7 +165,7 @@ class captchaSolver(reCaptcha):
|
|||||||
'action': 'usercaptchaupload',
|
'action': 'usercaptchaupload',
|
||||||
'interactive': 1,
|
'interactive': 1,
|
||||||
'file-upload-01': siteKey,
|
'file-upload-01': siteKey,
|
||||||
'oldsource': 'recaptchav2',
|
'oldsource': captchaMap[captchaType],
|
||||||
'pageurl': url,
|
'pageurl': url,
|
||||||
'maxtimeout': self.maxtimeout,
|
'maxtimeout': self.maxtimeout,
|
||||||
'json': 1
|
'json': 1
|
||||||
@@ -186,11 +190,6 @@ class captchaSolver(reCaptcha):
|
|||||||
if not reCaptchaParams.get('api_key'):
|
if not reCaptchaParams.get('api_key'):
|
||||||
raise reCaptchaParameter("9kw: Missing api_key parameter.")
|
raise reCaptchaParameter("9kw: Missing api_key parameter.")
|
||||||
|
|
||||||
if captchaType == 'hCaptcha':
|
|
||||||
raise reCaptchaException(
|
|
||||||
'Provider does not support hCaptcha.'
|
|
||||||
)
|
|
||||||
|
|
||||||
self.api_key = reCaptchaParams.get('api_key')
|
self.api_key = reCaptchaParams.get('api_key')
|
||||||
|
|
||||||
if reCaptchaParams.get('maxtimeout'):
|
if reCaptchaParams.get('maxtimeout'):
|
||||||
@@ -200,7 +199,7 @@ class captchaSolver(reCaptcha):
|
|||||||
self.session.proxies = reCaptchaParams.get('proxies')
|
self.session.proxies = reCaptchaParams.get('proxies')
|
||||||
|
|
||||||
try:
|
try:
|
||||||
jobID = self.requestSolve(url, siteKey)
|
jobID = self.requestSolve(captchaType, url, siteKey)
|
||||||
return self.requestJob(jobID)
|
return self.requestJob(jobID)
|
||||||
except polling.TimeoutException:
|
except polling.TimeoutException:
|
||||||
raise reCaptchaTimeout(
|
raise reCaptchaTimeout(
|
||||||
|
|||||||
@@ -26,7 +26,7 @@ from . import reCaptcha
|
|||||||
class captchaSolver(reCaptcha):
|
class captchaSolver(reCaptcha):
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
if sys.modules['python_anticaptcha'].__version__ < 0.6:
|
if sys.modules['python_anticaptcha'].__version__ < '0.6':
|
||||||
raise ImportError(
|
raise ImportError(
|
||||||
"Please upgrade the python module 'python_anticaptcha' via "
|
"Please upgrade the python module 'python_anticaptcha' via "
|
||||||
"pip install -U python-anticaptcha or https://github.com/ad-m/python-anticaptcha/"
|
"pip install -U python-anticaptcha or https://github.com/ad-m/python-anticaptcha/"
|
||||||
|
|||||||
Reference in New Issue
Block a user