139 lines
4.9 KiB
Python
139 lines
4.9 KiB
Python
from math import log
|
||
import random
|
||
from re import S
|
||
import time
|
||
from tkinter import N
|
||
from DrissionPage import Chromium
|
||
from loguru import logger
|
||
from work import get_random_canada_info
|
||
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)
|
||
self.tab = self.browser.latest_tab
|
||
pass
|
||
|
||
# cf打码
|
||
def solve_cloudflare(self, is_ok: bool = False):
|
||
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)
|
||
if res:
|
||
logger.error("Cloudflare验证失败")
|
||
return False
|
||
|
||
try:
|
||
shadow1 = tab.ele(
|
||
'x://*[@name="cf-turnstile-response"]').parent().shadow_root
|
||
iframe = shadow1.get_frame(1)
|
||
if iframe:
|
||
logger.debug("找到Cloudflare iframe")
|
||
shadow2 = iframe.ele('x:/html/body').shadow_root
|
||
if shadow2:
|
||
logger.debug("找到Cloudflare iframe body shadow root")
|
||
status = shadow2.ele(
|
||
'x://span[text()="Verifying..."]', timeout=1.5)
|
||
if status:
|
||
logger.debug("Cloudflare验证中,等待3秒")
|
||
tab.wait(3)
|
||
status = shadow2.ele(
|
||
'x://span[text()="Success!"]', timeout=1.5)
|
||
if status:
|
||
logger.debug("Cloudflare验证成功")
|
||
return True
|
||
checkbox = shadow2.ele(
|
||
'x://input[@type="checkbox"]', timeout=1.5)
|
||
if checkbox:
|
||
logger.debug("点击Cloudflare复选框")
|
||
checkbox.click()
|
||
tab.wait(3)
|
||
logger.debug("重新获取状态")
|
||
# 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
|
||
|
||
def wait_home(self):
|
||
logger.debug("等待进入首页")
|
||
jc = 0
|
||
while True:
|
||
if jc > 3:
|
||
logger.error("等待进入首页超过5次,未成功")
|
||
return False
|
||
self.tab.wait(1)
|
||
# 判断cf是否通过
|
||
bol = self.solve_cloudflare()
|
||
if not bol:
|
||
logger.debug("Cloudflare验证失败.")
|
||
# 刷新网页
|
||
self.tab.refresh()
|
||
self.tab.wait(1.5)
|
||
jc += 1
|
||
continue
|
||
else:
|
||
logger.debug("Cloudflare验证成功.")
|
||
self.tab.wait(1.5)
|
||
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_TIMED_OUT', timeout=1)
|
||
if bol:
|
||
logger.debug("刷新网页")
|
||
self.tab.refresh()
|
||
self.tab.wait(1.5)
|
||
bol = self.tab.ele(
|
||
't:div@text():ERR_SSL_PROTOCOL_ERROR', timeout=1)
|
||
if bol:
|
||
logger.debug("刷新网页")
|
||
self.tab.refresh()
|
||
self.tab.wait(1.5)
|
||
bol = self.tab.ele(
|
||
't:div@text():ERR_SOCKS_CONNECTION_FAILED', timeout=1)
|
||
if bol:
|
||
logger.debug("刷新网页")
|
||
self.tab.refresh()
|
||
self.tab.wait(1.5)
|
||
html = self.tab.url
|
||
logger.debug(f"当前URL: {html}")
|
||
if 'https://veritaconnect.ca/canadianbreadsettlement/en-us' == html:
|
||
logger.debug("成功进入首页")
|
||
return True
|
||
jc += 1
|
||
|
||
def open_url(self, url: str):
|
||
self.tab.get(url)
|
||
|
||
|
||
def main():
|
||
browser_id = bit_browser.bit_browser_create(
|
||
remark=f"us.novproxy.io:1000:ozua8623-region-CA-st-Ontario-city-Toronto:6wdcv4gq",
|
||
host="us.novproxy.io",
|
||
port=1000,
|
||
proxy_user="ozua8623-region-CA-st-Alberta-city-Calgary",
|
||
proxy_pwd="6wdcv4gq",
|
||
proxy_type='socks5'
|
||
)
|
||
http = bit_browser.bit_browser_open(browser_id)
|
||
logger.debug(f"打开浏览器 {browser_id}, http: {http}")
|
||
auto = Auto(http)
|
||
auto.open_url(
|
||
"https://veritaconnect.ca/canadianbreadsettlement/en-us/Claimant/UnknownClaimForm")
|
||
auto.wait_home()
|
||
|
||
if __name__ == '__main__':
|
||
main() |