Bladeren bron

反爬通用方法更新

lizongze 1 jaar geleden
bovenliggende
commit
5fd7c81383

+ 56 - 0
FworkSpider/crawl_func/PYCCS_cookies.py

@@ -0,0 +1,56 @@
+# -*- coding: utf-8 -*-
+"""
+Created on 2023-09-08 
+---------
+@summary: 进入前检查浏览器 PYCCS
+---------
+@author: Lzz
+"""
+import requests
+import re
+import execjs
+
+
+
+def get_PYCCS_ck(url,headers,proxies=False):
+
+    session = requests.session()
+    session.proxies = proxies
+
+    ex_js = '''
+    function get_ck(a,b,c) {
+        var x08c924 = parseInt(a);
+        x08c924 = x08c924 * parseInt(b);
+        x08c924 = x08c924 + parseInt(c);
+        x08c924 = (x08c924 * 0x3 + 0x7);
+        if (x08c924 < 0x7b)
+            x08c924 = x08c924 + 0x929;
+        if (x08c924 > 0x929)
+            x08c924 = Math['floor'](x08c924 / 0x7b);
+        return x08c924
+    }
+    '''
+    ctx = execjs.compile(ex_js)
+    count = 0
+    while count < 3:
+        try:
+            res = session.get(url, headers=headers, timeout=60,verify=False)
+
+            pm_data = "".join(re.findall('\|function\|(.*?)\|version\|',res.text,re.S)).split('|')
+
+            answer = ctx.call('get_ck',pm_data[1],pm_data[3],pm_data[-1])
+
+            data = {
+                "answer": f"{answer}"
+            }
+            resp = session.post(url.split('?')[0], headers=headers, data=data,timeout=60,verify=False)
+            cookies = session.cookies.get_dict()
+
+            if re.findall('\|function\|(.*?)\|version\|',resp.text,re.S):
+                print(f"请求解析异常!重试 {count} 次")
+                count += 1
+            else:
+                return cookies
+        except:
+            print("cookies_PYCCS 获取失败!")
+            return {}

+ 0 - 0
FworkSpider/untils/ali_slide_verify.py → FworkSpider/crawl_func/ali_slide_verify.py


+ 1 - 1
FworkSpider/untils/jsl_5s.py → FworkSpider/crawl_func/jsl_5s.py

@@ -74,7 +74,7 @@ class DTCookiePool(PageCookiePool):
                         location = window.location;
                         ''' + js_func
             ctx = execjs.compile(js_func)
-            # with open('ex_js.js', 'w+', encoding='utf-8') as f:
+            # with open('wzjyjt_xxgg_pm.js', 'w+', encoding='utf-8') as f:
             #     f.write(js_func)
 
             ss = ctx.call("go", json.loads(js_do_data))

+ 2 - 1
FworkSpider/untils/jsl_clearance_s.py → FworkSpider/crawl_func/jsl_clearance_s.py

@@ -70,7 +70,7 @@ class DTCookiePool(PageCookiePool):
                     location = window.location;
                     ''' + js_func
         ctx = execjs.compile(js_func)
-        # with open('ex_js.js', 'w+', encoding='utf-8') as f:
+        # with open('wzjyjt_xxgg_pm.js', 'w+', encoding='utf-8') as f:
         #     f.write(js_func)
         try:
             ss = ctx.call("go", json.loads(js_do_data))
@@ -82,3 +82,4 @@ class DTCookiePool(PageCookiePool):
             return cookies
         except Exception as e:
             pass
+