diff --git a/main.py b/main.py index ca8babc..13ff7c8 100644 --- a/main.py +++ b/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: diff --git a/spider/task.py b/spider/task.py index 1297446..71eb5c9 100644 --- a/spider/task.py +++ b/spider/task.py @@ -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"