0.1.0
This commit is contained in:
@@ -10,6 +10,7 @@ from mail_ import mail_
|
||||
from bit_browser import bit_browser
|
||||
from api import api
|
||||
|
||||
|
||||
class Auto:
|
||||
def __init__(self, http: str = None):
|
||||
self.browser = Chromium(http)
|
||||
@@ -17,9 +18,9 @@ class Auto:
|
||||
pass
|
||||
|
||||
# cf打码
|
||||
def solve_cloudflare(self):
|
||||
def solve_cloudflare(self, is_ok: bool = False):
|
||||
tab = self.browser.latest_tab
|
||||
for _ in range(5):
|
||||
for _ in range(3):
|
||||
self.tab.wait(1)
|
||||
try:
|
||||
shadow1 = tab.ele(
|
||||
@@ -31,16 +32,16 @@ class Auto:
|
||||
if shadow2:
|
||||
logger.debug("找到Cloudflare iframe body shadow root")
|
||||
status = shadow2.ele(
|
||||
'x://span[text()="Verifying..."]', timeout=1)
|
||||
'x://span[text()="Verifying..."]', timeout=1.5)
|
||||
if status:
|
||||
tab.wait(3)
|
||||
status = shadow2.ele(
|
||||
'x://span[text()="Success!"]', timeout=1)
|
||||
'x://span[text()="Success!"]', timeout=1.5)
|
||||
if status:
|
||||
logger.debug("Cloudflare验证成功")
|
||||
return True
|
||||
checkbox = shadow2.ele(
|
||||
'x://input[@type="checkbox"]', timeout=1)
|
||||
'x://input[@type="checkbox"]', timeout=1.5)
|
||||
if checkbox:
|
||||
checkbox.click()
|
||||
logger.debug("点击Cloudflare复选框")
|
||||
@@ -49,8 +50,10 @@ class Auto:
|
||||
# return False
|
||||
except Exception as e:
|
||||
# logger.error(f"处理Cloudflare异常: {e}")
|
||||
if is_ok:
|
||||
logger.debug(f"cloudflare处理通过: {e}")
|
||||
return True
|
||||
return self.solve_cloudflare(is_ok=True)
|
||||
tab.wait(1)
|
||||
return False
|
||||
|
||||
@@ -75,11 +78,13 @@ class Auto:
|
||||
else:
|
||||
logger.debug("Cloudflare验证成功.")
|
||||
self.tab.wait(1.5)
|
||||
bol = self.tab.ele('t:h1@text():Sorry, you have been blocked', timeout=1)
|
||||
bol = self.tab.ele(
|
||||
't:h1@text():Sorry, you have been blocked', timeout=1)
|
||||
if bol:
|
||||
logger.debug("ip被ban秒")
|
||||
return False
|
||||
bol = self.tab.ele('t:div@text():ERR_SSL_PROTOCOL_ERROR', timeout=1)
|
||||
bol = self.tab.ele(
|
||||
't:div@text():ERR_SSL_PROTOCOL_ERROR', timeout=1)
|
||||
if bol:
|
||||
logger.debug("刷新网页")
|
||||
self.tab.refresh()
|
||||
@@ -125,7 +130,8 @@ class Auto:
|
||||
logger.debug("异常界面")
|
||||
self.tab.wait(1)
|
||||
return self.click_continue(bl=True)
|
||||
bol = self.tab.ele('t:h2@text()=You are being rate limited', timeout=1)
|
||||
bol = self.tab.ele(
|
||||
't:h2@text()=You are being rate limited', timeout=1)
|
||||
if bol:
|
||||
logger.debug("被限流, 退出")
|
||||
return False
|
||||
@@ -166,7 +172,6 @@ class Auto:
|
||||
province = random.choice(list(cities.keys()))
|
||||
return province, random.choice(cities.get(province, []))
|
||||
|
||||
|
||||
def get_province_by_city(self, city: str) -> str | None:
|
||||
"""
|
||||
根据城市名称解析对应省份
|
||||
@@ -186,7 +191,6 @@ class Auto:
|
||||
}
|
||||
return mapping.get(city)
|
||||
|
||||
|
||||
# 随机实物
|
||||
def get_random_food(self, city: str, shop: str) -> list[str]:
|
||||
"""
|
||||
@@ -395,6 +399,8 @@ def get_proxy( city: str):
|
||||
|
||||
"""指纹浏览器操作"""
|
||||
# 创建指纹浏览器
|
||||
|
||||
|
||||
def create_fingerprint_browser(city: str):
|
||||
"""
|
||||
根据城市创建指纹浏览器并执行问卷流程
|
||||
@@ -448,6 +454,7 @@ def create_fingerprint_browser(city: str):
|
||||
except Exception as e:
|
||||
logger.error(f"{city} 删除浏览器异常: {e}")
|
||||
|
||||
|
||||
def run_city_forever(city: str):
|
||||
"""
|
||||
持续循环运行指定城市流程:完成一次即关闭并删除浏览器,然后重新创建继续运行
|
||||
@@ -462,6 +469,7 @@ def run_city_forever(city: str):
|
||||
logger.error(f"{city} 流程异常: {e}")
|
||||
time.sleep(2)
|
||||
|
||||
|
||||
def run_all_cities_concurrently():
|
||||
"""
|
||||
多线程并发运行所有城市流程
|
||||
@@ -471,7 +479,8 @@ def run_all_cities_concurrently():
|
||||
# cities = ['Calgary']
|
||||
threads = []
|
||||
for city in cities:
|
||||
t = threading.Thread(target=run_city_forever, args=(city,), name=f"{city}-thread")
|
||||
t = threading.Thread(target=run_city_forever,
|
||||
args=(city,), name=f"{city}-thread")
|
||||
t.start()
|
||||
threads.append(t)
|
||||
logger.info(f"{city} 线程已启动")
|
||||
@@ -480,6 +489,7 @@ def run_all_cities_concurrently():
|
||||
t.join()
|
||||
logger.info("所有城市流程执行完成")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
# auto = Auto()
|
||||
# auto.get_random_food('a')
|
||||
|
||||
Reference in New Issue
Block a user