This commit is contained in:
2025-11-21 12:17:41 +08:00
parent 9f5c71921e
commit a5f5206197

View File

@@ -22,11 +22,12 @@ class Auto:
tab = self.browser.latest_tab
for _ in range(5):
tab.wait(1)
res = tab.ele('t:h1@text()=Sorry, you have been blocked',timeout=1)
res = tab.ele(
't:h1@text()=Sorry, you have been blocked', timeout=1)
if res:
logger.error("Cloudflare验证失败")
return False
try:
shadow1 = tab.ele(
'x://*[@name="cf-turnstile-response"]').parent().shadow_root
@@ -88,7 +89,7 @@ class Auto:
logger.debug("Cloudflare验证成功.")
self.tab.wait(1.5)
bol = self.tab.ele(
't:h1@text():Sorry, you have been blocked', timeout=1)
't:h1@text()=Sorry, you have been blocked', timeout=1)
if bol:
logger.debug("ip被ban秒")
return False
@@ -143,6 +144,15 @@ class Auto:
# logger.debug("异常界面")
# self.tab.wait(1)
# return self.click_continue(bl=True)
bol = self.tab.ele(
't:h1@text()=Sorry, you have been blocked', timeout=1)
if bol:
logger.debug("ip被ban秒")
# 刷新网页
self.tab.refresh()
self.tab.wait(1.5)
bol = self.tab.ele(
't:h2@text()=You are being rate limited', timeout=1)
if bol:
@@ -243,9 +253,9 @@ class Auto:
}
# 随机返回一条 key 和 value
return random.choice(list(mapping.items()))
# 随机实物
def get_random_food(self, city: str, shop: str) -> list[str]:
"""
随机选择 1~2 种食物类别,并为每个类别至少选择 1 个具体产品
@@ -408,33 +418,47 @@ class Auto:
self.tab.ele(
't:input@id=PrintName').set.value(last_name+' '+first_name)
self.tab.wait(0.1)
for i in range(3):
bol = self.solve_cloudflare()
if not bol:
logger.debug("Cloudflare验证失败.")
self.tab.wait(0.1)
else:
logger.debug("Cloudflare验证成功.")
self.tab.wait(3)
logger.debug(f"点击Submit按钮")
self.tab.ele('t:button@text():Submit').click()
break
api.create_info(
first_name=first_name,
last_name=last_name,
birthday=birthday,
current_address=current_address,
city=city,
phone=phone,
postal_code=postal_code,
province=province,
email=email,
text=text
)
self.tab.wait(3)
return self.submit_file(first_name, last_name, birthday, current_address, city, phone, postal_code, province, email, text)
except Exception as e:
logger.error(f"填写问卷失败: {e}")
# 提交问卷
def submit_file(self, first_name: str, last_name: str, birthday: str, current_address: str, city: str, phone: str, postal_code: str, province: str, email: str, text: str):
jc = 0
while True:
if jc >= 3:
logger.error("提交问卷失败")
return False
res = self.tab.ele(
't:h2@text()=CLAIM SUBMISSION CONFIRMATION', timeout=3)
if res:
logger.info("提交问卷成功")
api.create_info(
first_name=first_name,
last_name=last_name,
birthday=birthday,
current_address=current_address,
city=city,
phone=phone,
postal_code=postal_code,
province=province,
email=email,
text=text
)
return True
bol = self.solve_cloudflare()
if not bol:
logger.debug("Cloudflare验证失败.")
self.tab.wait(1)
else:
logger.debug("Cloudflare验证成功.")
logger.debug(f"点击Submit按钮")
self.tab.ele('t:button@text():Submit').click()
self.tab.wait(3)
jc += 1
# 取对应城市的代理
def get_proxy(city: str):
@@ -451,6 +475,7 @@ def get_proxy(city: str):
else:
return None
def get_random_proxy() -> list[str] | None:
"""
随机选择一个代理配置(按指纹浏览器数量随机取 IP
@@ -467,6 +492,7 @@ def get_random_proxy() -> list[str] | None:
except Exception:
return None
"""指纹浏览器操作"""
# 创建指纹浏览器
@@ -560,7 +586,8 @@ def run_all_cities_concurrently(num: int):
import threading
threads = []
for i in range(num):
t = threading.Thread(target=run_random_ips_forever, name=f"random-ip-thread-{i}")
t = threading.Thread(target=run_random_ips_forever,
name=f"random-ip-thread-{i}")
t.start()
threads.append(t)
logger.info(f"随机 IP 线程 {i} 已启动")
@@ -594,7 +621,8 @@ def run_random_ips_concurrently(num: int):
return
threads = []
for i in range(num):
t = threading.Thread(target=run_random_ips_forever, name=f"random-ip-thread-{i}")
t = threading.Thread(target=run_random_ips_forever,
name=f"random-ip-thread-{i}")
t.start()
threads.append(t)
logger.info(f"随机 IP 线程 {i} 已启动")