From 818e9b77ee265f33e3ac04cacfbc3c10c21a54a5 Mon Sep 17 00:00:00 2001 From: JackDandy Date: Thu, 5 Apr 2018 01:23:27 +0100 Subject: [PATCH] Fix cf algorythm. --- CHANGES.md | 7 ++++++- lib/cfscrape.py | 6 ++++-- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index c7d5c372..828ed7da 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -1,4 +1,9 @@ -### 0.15.5 (2018-04-04 21:10:00 UTC) +### 0.15.6 (2018-04-05 01:20:00 UTC) + +* Fix cf algorythm + + +### 0.15.5 (2018-04-04 21:10:00 UTC) * Remove GFT torrent provider diff --git a/lib/cfscrape.py b/lib/cfscrape.py index b15f9783..f4fb4361 100644 --- a/lib/cfscrape.py +++ b/lib/cfscrape.py @@ -82,7 +82,7 @@ class CloudflareScraper(Session): raise # Safely evaluate the Javascript expression - params['jschl_answer'] = str(int(js2py.eval_js(js)) + len(domain)) + params['jschl_answer'] = str(js2py.eval_js(js) + len(domain)) # Requests transforms any request into a GET after a redirect, # so the redirect has to be handled manually here to allow for @@ -96,8 +96,10 @@ class CloudflareScraper(Session): def extract_js(body): js = re.search(r'setTimeout\(function\(\){\s+(var ' 's,t,o,p,b,r,e,a,k,i,n,g,f.+?\r?\n[\s\S]+?a\.value =.+?)\r?\n', body).group(1) - js = re.sub(r'a\.value = (parseInt\(.+?\)).+', r'\1', js) + js = re.sub(r'a\.value\s=\s([+]?.+?)\s?\+\s?[^\.]+\.length.*', r'\1', js) + js = re.sub(r'a\.value\s=\s(parseInt\(.+?\)).+', r'\1', js) js = re.sub(r'\s{3,}[a-z](?: = |\.).+', '', js) + js = re.sub(r';\s+;', ';', js) # Strip characters that could be used to exit the string context # These characters are not currently used in Cloudflare's arithmetic snippet