Browse Source

feat: 新增文心一言 session检查功能

master
zzx 3 months ago
parent
commit
e7c780c322
  1. 17
      spiders/ai_seo/yiyan.py

17
spiders/ai_seo/yiyan.py

@ -168,7 +168,6 @@ class YiYanSpider(AbstractAiSeoSpider):
)) ))
self.ai_answer.search_result = ai_search_result_list self.ai_answer.search_result = ai_search_result_list
async def check_login(self): async def check_login(self):
# 找登录后才会出现的侧边栏 # 找登录后才会出现的侧边栏
try: try:
@ -182,6 +181,22 @@ class YiYanSpider(AbstractAiSeoSpider):
await AiSeoApis.update_spider_session(self.session_info['id'], 2) await AiSeoApis.update_spider_session(self.session_info['id'], 2)
raise Exception(f"{self.get_platform_name()}登录失败 session_id: {self.session_info['id']}") raise Exception(f"{self.get_platform_name()}登录失败 session_id: {self.session_info['id']}")
async def do_check_session(self) -> bool:
try:
await self.browser_page.goto(self.get_home_url(), timeout=200000)
await asyncio.sleep(2)
# 检查登录状态
await self.check_login()
# 开始操作
chat_input_element = self.browser_page.locator("//div[@class='yc-editor']")
await chat_input_element.click()
await asyncio.sleep(2)
# 输入提问词
await self.browser_page.keyboard.insert_text(self.prompt)
return True
except Exception:
return False
def get_platform_id(self) -> int: def get_platform_id(self) -> int:
return 6 return 6

Loading…
Cancel
Save