Преглед изворни кода

修复浏览器指纹验证缺失,导致采集失败问题

dzr пре 3 месеци
родитељ
комит
98fc0f5b62
2 измењених фајлова са 98 додато и 4 уклоњено
  1. 49 2
      a_gtcgpt_cggg/fingerprint.py
  2. 49 2
      a_gtcgpt_cgjg/fingerprint.py

+ 49 - 2
a_gtcgpt_cggg/fingerprint.py

@@ -7,9 +7,11 @@ Created on 2025-02-08
 @author: Dzr
 """
 import json
-import execjs
-from pathlib import Path
 import random
+from pathlib import Path
+
+import execjs
+import requests
 
 
 def random_fp():
@@ -56,6 +58,51 @@ def get_fingerprint():
     return ctx.call('getFingerprint', fp_data)
 
 
+def check_fingerprint(fp, cookies, referer, proxies=None):
+    url = 'https://cg.95306.cn/proxy/portal/elasticSearch/checkRequestNumValidateCode'
+
+    headers = {
+        'Accept': '*/*',
+        'Accept-Language': 'zh-CN,zh;q=0.9,en;q=0.8',
+        'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8',
+        'Origin': 'https://cg.95306.cn',
+        'Referer': referer,
+        'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/128.0.0.0 Safari/537.36',
+        'X-Requested-With': 'XMLHttpRequest',
+    }
+
+    data = {
+        'mhId': fp,
+    }
+
+    try:
+        response = requests.post(
+            url,
+            cookies=cookies,
+            headers=headers,
+            data=data,
+            proxies=proxies,
+            timeout=10
+        )
+        response.raise_for_status()
+        return True
+    except requests.RequestException:
+        return False
+
+
+def fetch_alteon_pcgmh(proxies=None):
+    url = 'https://cg.95306.cn/assets/crmsc/js/v4.js'
+    headers = {
+        'Accept': '*/*',
+        'Accept-Language': 'zh-CN,zh;q=0.9,en;q=0.8',
+        'Origin': 'https://cg.95306.cn',
+        'Referer': 'https://cg.95306.cn/assets/crmsc/js/getMhId.js',
+        'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/128.0.0.0 Safari/537.36',
+    }
+    response = requests.get(url, headers=headers, proxies=proxies, timeout=10)
+    return response.cookies.get('AlteonPcgmh')
+
+
 if __name__ == '__main__':
     for _ in range(3):
         print(get_fingerprint())

+ 49 - 2
a_gtcgpt_cgjg/fingerprint.py

@@ -7,9 +7,11 @@ Created on 2025-02-08
 @author: Dzr
 """
 import json
-import execjs
-from pathlib import Path
 import random
+from pathlib import Path
+
+import execjs
+import requests
 
 
 def random_fp():
@@ -56,6 +58,51 @@ def get_fingerprint():
     return ctx.call('getFingerprint', fp_data)
 
 
+def check_fingerprint(fp, cookies, referer, proxies=None):
+    url = 'https://cg.95306.cn/proxy/portal/elasticSearch/checkRequestNumValidateCode'
+
+    headers = {
+        'Accept': '*/*',
+        'Accept-Language': 'zh-CN,zh;q=0.9,en;q=0.8',
+        'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8',
+        'Origin': 'https://cg.95306.cn',
+        'Referer': referer,
+        'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/128.0.0.0 Safari/537.36',
+        'X-Requested-With': 'XMLHttpRequest',
+    }
+
+    data = {
+        'mhId': fp,
+    }
+
+    try:
+        response = requests.post(
+            url,
+            cookies=cookies,
+            headers=headers,
+            data=data,
+            proxies=proxies,
+            timeout=10
+        )
+        response.raise_for_status()
+        return True
+    except requests.RequestException:
+        return False
+
+
+def fetch_alteon_pcgmh(proxies=None):
+    url = 'https://cg.95306.cn/assets/crmsc/js/v4.js'
+    headers = {
+        'Accept': '*/*',
+        'Accept-Language': 'zh-CN,zh;q=0.9,en;q=0.8',
+        'Origin': 'https://cg.95306.cn',
+        'Referer': 'https://cg.95306.cn/assets/crmsc/js/getMhId.js',
+        'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/128.0.0.0 Safari/537.36',
+    }
+    response = requests.get(url, headers=headers, proxies=proxies, timeout=10)
+    return response.cookies.get('AlteonPcgmh')
+
+
 if __name__ == '__main__':
     for _ in range(3):
         print(get_fingerprint())