mirror of
https://github.com/mikf/gallery-dl.git
synced 2024-11-22 10:42:34 +01:00
cache cookies from cloudflare-bypass
This commit is contained in:
parent
2b93fdba7c
commit
e78937a580
@ -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 = {}
|
||||
|
Loading…
Reference in New Issue
Block a user