This commit is contained in:
Relakkes 2023-12-16 00:12:20 +08:00
parent 40cbd9f4d7
commit f85fd97d25
2 changed files with 8 additions and 4 deletions

View File

@ -14,8 +14,8 @@ IP_PROXY_POOL_COUNT = 2
# 重试时间 # 重试时间
RETRY_INTERVAL = 60 * 30 # 30 minutes RETRY_INTERVAL = 60 * 30 # 30 minutes
# playwright headless # 无头浏览器的标识True:开启 False 关闭(会打开一个浏览器)
HEADLESS = True HEADLESS = False
# 是否保存登录状态 # 是否保存登录状态
SAVE_LOGIN_STATE = True SAVE_LOGIN_STATE = True

View File

@ -28,13 +28,17 @@ class XHSLogin(AbstractLogin):
self.login_phone = login_phone self.login_phone = login_phone
self.cookie_str = cookie_str self.cookie_str = cookie_str
@retry(stop=stop_after_attempt(20), wait=wait_fixed(1), retry=retry_if_result(lambda value: value is False)) @retry(stop=stop_after_attempt(120), wait=wait_fixed(1), retry=retry_if_result(lambda value: value is False))
async def check_login_state(self, no_logged_in_session: str) -> bool: async def check_login_state(self, no_logged_in_session: str) -> bool:
""" """
Check if the current login status is successful and return True otherwise return False Check if the current login status is successful and return True otherwise return False
retry decorator will retry 20 times if the return value is False, and the retry interval is 1 second retry decorator will retry 20 times if the return value is False, and the retry interval is 1 second
if max retry times reached, raise RetryError if max retry times reached, raise RetryError
""" """
if "请通过验证" in await self.context_page.content():
utils.logger.info("登录过程中出现验证码,请手动验证")
current_cookie = await self.browser_context.cookies() current_cookie = await self.browser_context.cookies()
_, cookie_dict = utils.convert_cookies(current_cookie) _, cookie_dict = utils.convert_cookies(current_cookie)
current_web_session = cookie_dict.get("web_session") current_web_session = cookie_dict.get("web_session")
@ -157,7 +161,7 @@ class XHSLogin(AbstractLogin):
partial_show_qrcode = functools.partial(utils.show_qrcode, base64_qrcode_img) partial_show_qrcode = functools.partial(utils.show_qrcode, base64_qrcode_img)
asyncio.get_running_loop().run_in_executor(executor=None, func=partial_show_qrcode) asyncio.get_running_loop().run_in_executor(executor=None, func=partial_show_qrcode)
utils.logger.info(f"waiting for scan code login, remaining time is 20s") utils.logger.info(f"waiting for scan code login, remaining time is 120s")
try: try:
await self.check_login_state(no_logged_in_session) await self.check_login_state(no_logged_in_session)
except RetryError: except RetryError: