判断是否被检测自动化增加文本条件, 登录, 获取账号信息, 修改账号信息, 检查账号cookies为无头模式运行. 获取任务更改为2个工作线程防止队列任务过多
This commit is contained in:
7
main.py
7
main.py
@@ -79,15 +79,15 @@ def main():
|
||||
# 存储正在运行的任务
|
||||
running_tasks = set()
|
||||
|
||||
# 创建线程池执行任务(3个工作线程)
|
||||
with ThreadPoolExecutor(max_workers=3) as executor:
|
||||
# 创建线程池执行任务(2个工作线程)
|
||||
with ThreadPoolExecutor(max_workers=2) as executor:
|
||||
while True:
|
||||
try:
|
||||
# 清理已完成的任务
|
||||
running_tasks = {task for task in running_tasks if not task.done()}
|
||||
|
||||
# 如果队列未满,尝试获取新任务
|
||||
if len(running_tasks) < 3:
|
||||
if len(running_tasks) < 2:
|
||||
task = get_task()
|
||||
if task:
|
||||
logger.info(f"收到任务: {task['id']} - {task['task_type']}")
|
||||
@@ -102,6 +102,7 @@ def main():
|
||||
time.sleep(10)
|
||||
else:
|
||||
# 达到最大并发数时等待
|
||||
logger.info("等待任务完成")
|
||||
time.sleep(1)
|
||||
|
||||
except Exception as e:
|
||||
|
||||
@@ -835,7 +835,7 @@ def check_account_status(page, cookies):
|
||||
raise AuthException('该账户登录状态失效', 'invalid')
|
||||
|
||||
# 判断是否被检测到自动化,这种情况只需要点击按钮就可以继续
|
||||
if page.query_selector('//span[text()="We suspect automated behavior on your account"]') is not None:
|
||||
if page.query_selector('//span[text()="We suspect automated behaviour on your account" or text()="We suspect automated behavior on your account"]') is not None:
|
||||
page.click('//span[text()="Dismiss"]')
|
||||
time.sleep(3)
|
||||
retry_goto(page, 'https://www.facebook.com')
|
||||
@@ -1055,7 +1055,7 @@ def playwright_get_user_profile(cookies, username=None):
|
||||
with sync_playwright() as playwright:
|
||||
update_windows_distinguish()
|
||||
browser = playwright.chromium.launch(
|
||||
headless=False, args=['--start-maximized'], executable_path=path
|
||||
headless=True, args=['--start-maximized'], executable_path=path
|
||||
)
|
||||
context = browser.new_context(no_viewport=True)
|
||||
context.add_cookies(parse_cookies(cookies))
|
||||
@@ -1099,11 +1099,11 @@ def playwright_set_user_profile(cookies, username=None, first_name=None, last_na
|
||||
return
|
||||
|
||||
path = os.path.join(BASE_PATH, 'chrome', '130-0008', 'chrome.exe')
|
||||
with lock:
|
||||
with login_semaphore:
|
||||
with sync_playwright() as playwright:
|
||||
update_windows_distinguish()
|
||||
browser = playwright.chromium.launch(
|
||||
headless=False, args=['--start-maximized'], executable_path=path
|
||||
headless=True, args=['--start-maximized'], executable_path=path
|
||||
)
|
||||
context = browser.new_context(no_viewport=True)
|
||||
context.add_cookies(parse_cookies(cookies))
|
||||
@@ -1163,7 +1163,7 @@ def playwright_check_account_cookies(cookies):
|
||||
with sync_playwright() as playwright:
|
||||
update_windows_distinguish()
|
||||
browser = playwright.chromium.launch(
|
||||
headless=False, args=['--start-maximized'], executable_path=path
|
||||
headless=True, args=['--start-maximized'], executable_path=path
|
||||
)
|
||||
context = browser.new_context(no_viewport=True)
|
||||
context.add_cookies(parse_cookies(cookies))
|
||||
@@ -1351,7 +1351,7 @@ def playwright_m_login(username, password, code_2fa=None):
|
||||
with sync_playwright() as playwright:
|
||||
update_windows_distinguish()
|
||||
browser = playwright.chromium.launch(
|
||||
headless=False, args=['--start-maximized'], executable_path=path
|
||||
headless=True, args=['--start-maximized'], executable_path=path
|
||||
)
|
||||
# random_user_agent = UserAgent().getBrowser(["Chrome Mobile iOS"]).get("useragent")
|
||||
random_user_agent = "Mozilla/5.0 (Linux; Android 12; Pixel 6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/101.0.4951.41 Mobile Safari/537.36"
|
||||
|
||||
Reference in New Issue
Block a user