1
0
mirror of https://github.com/mikf/gallery-dl.git synced 2024-11-22 02:32:33 +01:00

cache cookies from cloudflare-bypass

This commit is contained in:
Mike Fährmann 2015-11-27 21:32:07 +01:00
parent 2b93fdba7c
commit e78937a580
No known key found for this signature in database
GPG Key ID: 5680CA389D365A88

View File

@ -16,6 +16,9 @@ from . import text
def bypass_ddos_protection(session, url):
"""Prepare a requests.session to access 'url' behind Cloudflare protection"""
session.headers["Referer"] = url
if url in _cache:
session.cookies.update(_cache[url])
return
page = session.get(url).text
params = text.extract_all(page, (
('jschl_vc', 'name="jschl_vc" value="', '"'),
@ -24,6 +27,7 @@ def bypass_ddos_protection(session, url):
params["jschl_answer"] = solve_jschl(url, page)
time.sleep(4)
session.get(urllib.parse.urljoin(url, "/cdn-cgi/l/chk_jschl"), params=params)
_cache[url] = session.cookies.copy()
def solve_jschl(url, page):
"""Solve challenge to get 'jschl_answer' value"""
@ -75,3 +79,5 @@ expression_values = {
"!+": 1,
"+!!": 1,
}
_cache = {}