diff --git a/main.py b/main.py index 02de29b..c4d253c 100644 --- a/main.py +++ b/main.py @@ -23,8 +23,8 @@ def get_task(): 'Content-Type': 'application/json' } data = { - "include_task_type": [], - "exclude_task_type": ["login_account"], + "include_task_type": ["login_account"], + "exclude_task_type": [] } response = requests.post(url, headers=header, json=data) if response.status_code == 200: @@ -61,19 +61,18 @@ def execute_task(tid, task_type, **kwargs): def main(): - with ThreadPoolExecutor(max_workers=1) as t: - while True: - try: - task = get_task() - if task is None: - time.sleep(10) - continue - task['data']['tid'] = task['id'] - task['data']['task_type'] = task['task_type'] - t.submit(execute_task, **task['data']) - except Exception as e: - error_logger.error(f'Main Error: {e}') + while True: + try: + task = get_task() + if task is None: time.sleep(10) + continue + task['data']['tid'] = task['id'] + task['data']['task_type'] = task['task_type'] + execute_task(**task['data']) + except Exception as e: + error_logger.error(f'Main Error: {e}') + time.sleep(10) if __name__ == '__main__': diff --git a/spider/task.py b/spider/task.py index e2c5f75..3844a5f 100644 --- a/spider/task.py +++ b/spider/task.py @@ -1170,6 +1170,7 @@ def get_login_continue_btn(page): def playwright_login(username, password, code_2fa=None): + error_logger.info(f"登录账号{username}") # 检查是否冻结 check_freeze_account(username) @@ -1210,19 +1211,17 @@ def playwright_login(username, password, code_2fa=None): page.reload() time.sleep(random.randint(1, 3)) - captcha_img = page.query_selector_all('//img[contains(@src, "captcha")]') + captcha_img = page.query_selector('//img[contains(@src, "captcha")]') if captcha_img: - img_file_path = os.path.join(BASE_PATH, 'files', 'captcha.png') - captcha_img[0].screenshot(path=img_file_path) - with open(img_file_path, 'rb') as f: - data = { - 'user': 'shaowz', - 'pass2': '69e86586e8a1241719ebacecf7bb84c2', - 'softid': '951004', - 'codetype': '3006', - } - response = requests.post('http://upload.chaojiying.net/Upload/Processing.php', - data=data, timeout=60, files={'userfile': f}) + error_logger.info(f"账号{username} 需要验证") + data = { + 'user': 'ycxxkj', + 'pass2': 'B4DBF06831577C6558F823879061626C', + 'softid': '951004', + 'codetype': '3006', + } + response = requests.post('http://upload.chaojiying.net/Upload/Processing.php', data=data, + timeout=60, files={'userfile': ('ccc.jpg', captcha_img.screenshot())}) result = response.json() if result['err_no'] == 0: pic_str = result['pic_str'] @@ -1243,6 +1242,7 @@ def playwright_login(username, password, code_2fa=None): ] if not h2.text_content() in text_contexts: + error_logger.info(f"账号{username} 操作失败") raise OperationFailed("操作失败") auth_span = page.query_selector('//span[text()="Try Another Way" or text()="Try another way"]') if auth_span: @@ -1261,8 +1261,8 @@ def playwright_login(username, password, code_2fa=None): time.sleep(1) page.locator('//label[text()="Code"]/preceding-sibling::input').fill(auth_code) page.click('//span[text()="Continue"]') - # 这里验证可能会很慢, 做显示等待 - time.sleep(10) + # 这里验证可能会很慢, 硬等 + time.sleep(40) save_profile = page.query_selector('//span[text()="Save"]') if save_profile: save_profile.click()