Sfoglia il codice sorgente

refactor: add pre-visiting domain root for cloudflare bypass in tls plugins and keygen, and update configurations

jerry 1 mese fa
parent
commit
84cd7d60dd
3 ha cambiato i file con 45 aggiunte e 7 eliminazioni
  1. 3 3
      config/test_conf.yaml
  2. 25 1
      plugins/tls_plugin.py
  3. 17 3
      tls_keygen.py

+ 3 - 3
config/test_conf.yaml

@@ -93,7 +93,7 @@ plugins:
   tls_plugin:
     group_id: tls.cn.sha.fr
     account:
-      username: hujiarui8@text.skin
+      username: test_sha@text.skin
       password: Visafly@111
     appointment_types:
     - city: Shanghai
@@ -226,8 +226,8 @@ plugins:
     group_id: pernotami.ie.it
     debug: false
     account:
-      username: waynezhang.luck@gmail.com
-      password: '!Wei19960506'
+      username: orlaflynn3152@text.skin
+      password: 6@4yz4LetdcV
     appointment_types:
     - city: Dublin
       country: Italy

+ 25 - 1
plugins/tls_plugin.py

@@ -4,6 +4,7 @@ import random
 import re
 import os
 import uuid
+from urllib.parse import urlparse
 from datetime import datetime
 from typing import List, Dict, Optional, Any, Callable
 from DrissionPage import ChromiumPage, ChromiumOptions
@@ -503,9 +504,32 @@ class TlsPlugin(IPlugin):
         self.mouse = HumanMouse(self.page, timing=MOUSE_PROFILES[profile_name], debug=self.config.debug)
         self.keyboard = HumanKeyboard(self.page)
 
-        # 打开初始站点入口
+        # 打开初始站点入口:先访问对应主域名建立上下文与过盾,再跳转深层目标路径
         tls_url = self.free_config.get('tls_url', '')
         if tls_url:
+            parsed = urlparse(tls_url)
+            domain_url = f"{parsed.scheme}://{parsed.netloc}" if (parsed.scheme and parsed.netloc) else ''
+            
+            # 建立主站域名上下文,避免冷启动直接跳转深层路径导致被 Cloudflare 拦截
+            if domain_url and domain_url != tls_url:
+                self._log(f"Establishing domain context first: {domain_url}")
+                self.page.get(domain_url)
+                try:
+                    self.page.wait.load_start(timeout=5)
+                except Exception:
+                    pass
+                
+                # 若主站根域名触发 5秒盾挑战或等候室,先行穿透自愈
+                cf = CloudflareBypasser(self.page, log=self.config.debug if self.config else False, logger=self._log)
+                if not cf.is_bypassed():
+                    self._log("🛡️ Cloudflare challenge detected on domain root, bypassing...")
+                    cf.bypass(max_retry=3)
+                cf.handle_waiting_room(max_wait_sec=30)
+                
+                time.sleep(random.uniform(2.0, 3.5))
+                handle_cookie_consent(self.page)
+                time.sleep(random.uniform(0.5, 1.5))
+
             self._log(f"Navigating to entry: {tls_url}")
             self.page.get(tls_url)
 

+ 17 - 3
tls_keygen.py

@@ -11,7 +11,7 @@ import random
 import requests
 import argparse
 import concurrent.futures
-from urllib.parse import urlencode
+from urllib.parse import urlencode, urlparse
 from datetime import datetime
 from typing import Optional, Dict
 from DrissionPage.common import Keys
@@ -174,11 +174,25 @@ class TlsRegistrator:
         co.set_argument(f"--fingerprint-platform={specific_fp.get('platform')}")
         co.set_argument(f"--fingerprint-brand={specific_fp.get('brand')}")
         self.page = ChromiumPage(co)
+        
+        parsed = urlparse(self.tls_url)
+        domain_url = f"{parsed.scheme}://{parsed.netloc}" if (parsed.scheme and parsed.netloc) else ''
+        if domain_url and domain_url != self.tls_url:
+            self._log(f"正在建立主站域名访问上下文: {domain_url}")
+            self.page.get(domain_url)
+            time.sleep(3)
+            cf_bypasser = CloudflareBypasser(self.page, log=True)
+            if not cf_bypasser.is_bypassed():
+                cf_bypasser.bypass(max_retry=4)
+            cf_bypasser.handle_waiting_room(max_wait_sec=30)
+            time.sleep(1.5)
+
+        self._log(f"正在访问目标入口页面: {self.tls_url}")
         self.page.get(self.tls_url)
-        time.sleep(5)
+        time.sleep(3)
         cf_bypasser = CloudflareBypasser(self.page, log=True)
         cf_bypasser.bypass(max_retry=8)
-        time.sleep(3)
+        time.sleep(2)
         cf_bypasser.handle_waiting_room()
         
         self._log("正在初始化拟人化工具...")