From 713da7a455885bb5dc7d6a20c08fab33766c04ec Mon Sep 17 00:00:00 2001 From: zzx Date: Fri, 22 Aug 2025 10:20:33 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E9=80=82=E9=85=8D=E6=9C=80=E6=96=B0?= =?UTF-8?q?=E6=96=87=E5=BF=83=E4=B8=80=E8=A8=80=E7=BD=91=E9=A1=B5=E7=AB=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- spiders/ai_seo/yiyan.py | 25 ++++++++++--------------- 1 file changed, 10 insertions(+), 15 deletions(-) diff --git a/spiders/ai_seo/yiyan.py b/spiders/ai_seo/yiyan.py index 1d3efb7..344f5bc 100644 --- a/spiders/ai_seo/yiyan.py +++ b/spiders/ai_seo/yiyan.py @@ -28,18 +28,17 @@ class YiYanSpider(AbstractAiSeoSpider): async def _do_spider(self) -> AiAnswer: # 初始化数据 + self.think = True self._init_data() await self.browser_page.goto(self.get_home_url(), timeout=600000) await asyncio.sleep(2) # 检查登录状态 await self.check_login() if self.think: - think_btn = self.browser_page.locator("span:text('深度思考(X1 Turbo)')").locator('..') - clazz = (await think_btn.get_attribute('class')).split(' ') - if await think_btn.is_visible(): - if len(clazz) == 1: - await think_btn.click() - await asyncio.sleep(2) + think_btn = self.browser_page.locator("//span[text()='思考(X1 Turbo)']/parent::div") + clazz = await think_btn.get_attribute('class') + if 'active' not in clazz: + await think_btn.click() # 开始操作 chat_input_element = self.browser_page.locator("//div[@class='yc-editor']") await chat_input_element.click() @@ -64,7 +63,7 @@ class YiYanSpider(AbstractAiSeoSpider): raise self.fail_exception # 打开搜索结果 - open_search_btn_element = self.browser_page.locator("div:text('条网页信息源')") + open_search_btn_element = self.browser_page.locator(f"div:text('参考{len(self.ai_answer.search_result)}个网页')") if await open_search_btn_element.count() > 0: await open_search_btn_element.click() @@ -169,18 +168,14 @@ class YiYanSpider(AbstractAiSeoSpider): self.ai_answer.search_result = ai_search_result_list async def check_login(self): - # 找登录后才会出现的侧边栏 - try: - old_btn = self.browser_page.locator("//div[text()='返回旧版']") - if await old_btn.is_visible(): - await old_btn.click() - await asyncio.sleep(3) - await self.browser_page.locator("//div[@id='eb_sidebar']").wait_for(state='attached', timeout=20000) - except Exception: + # 找登录后按钮 + login_btn = self.browser_page.locator("//button[contains(@class, 'ebButton') and normalize-space(text())='登录']") + if await login_btn.count() > 0: # 更新session状态 await AiSeoApis.update_spider_session(self.session_info['id'], 2) 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)