1
0
mirror of https://github.com/mikf/gallery-dl.git synced 2025-01-31 19:51:34 +01:00

fix Cloudflare bypss

This commit is contained in:
Mike Fährmann 2019-12-01 01:07:24 +01:00
parent 8759403f37
commit e2710702d4
No known key found for this signature in database
GPG Key ID: 5680CA389D365A88
2 changed files with 16 additions and 20 deletions

View File

@ -35,10 +35,11 @@ def solve_challenge(session, response, kwargs):
cf_kwargs = {}
headers = cf_kwargs["headers"] = collections.OrderedDict()
params = cf_kwargs["params"] = collections.OrderedDict()
params = cf_kwargs["data"] = collections.OrderedDict()
page = response.text
params["s"] = text.extract(page, 'name="s" value="', '"')[0]
url = root + text.extract(page, 'action="', '"')[0]
params["r"] = text.extract(page, 'name="r" value="', '"')[0]
params["jschl_vc"] = text.extract(page, 'name="jschl_vc" value="', '"')[0]
params["pass"] = text.extract(page, 'name="pass" value="', '"')[0]
params["jschl_answer"] = solve_js_challenge(page, parsed.netloc)
@ -46,12 +47,14 @@ def solve_challenge(session, response, kwargs):
time.sleep(4)
url = root + "/cdn-cgi/l/chk_jschl"
cf_kwargs["allow_redirects"] = False
cf_response = session.request("GET", url, **cf_kwargs)
cf_response = session.request("POST", url, **cf_kwargs)
location = cf_response.headers.get("Location")
if not location:
cookies = {
cookie.name: cookie.value
for cookie in cf_response.cookies
}
if not cookies:
import logging
log = logging.getLogger("cloudflare")
rtype = "CAPTCHA" if is_captcha(cf_response) else "Unexpected"
@ -60,18 +63,9 @@ def solve_challenge(session, response, kwargs):
log.debug("Content:\n%s", cf_response.text)
raise exception.StopExtraction()
if location[0] == "/":
location = root + location
else:
location = re.sub(r"(https?):/(?!/)", r"\1://", location)
for cookie in cf_response.cookies:
if cookie.name == "cf_clearance":
return location, cookie.domain, {
cookie.name: cookie.value,
"__cfduid" : response.cookies.get("__cfduid", ""),
}
return location, "", {}
domain = next(iter(cf_response.cookies)).domain
cookies["__cfduid"] = response.cookies.get("__cfduid", "")
return cf_response, domain, cookies
def solve_js_challenge(page, netloc):

View File

@ -101,10 +101,12 @@ class Extractor():
raise exception.NotFoundError(notfound)
if cloudflare.is_challenge(response):
self.log.info("Solving Cloudflare challenge")
url, domain, cookies = cloudflare.solve_challenge(
response, domain, cookies = cloudflare.solve_challenge(
session, response, kwargs)
cloudflare.cookies.update(self.category, (domain, cookies))
if response.status_code >= 400:
continue
cloudflare.cookies.update(self.category, (domain, cookies))
return response
if cloudflare.is_captcha(response):
try:
import OpenSSL # noqa