diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..ba7a126 --- /dev/null +++ b/.gitignore @@ -0,0 +1,10 @@ +data +.idea +.vscode +.venv +venv +config.py +screenshot +Pipfile +Pipfile.lock +logs \ No newline at end of file diff --git a/spiders/ai_seo/yiyan.py b/spiders/ai_seo/yiyan.py index a34171c..b69c227 100644 --- a/spiders/ai_seo/yiyan.py +++ b/spiders/ai_seo/yiyan.py @@ -63,20 +63,24 @@ class YiYanSpider(AbstractAiSeoSpider): if self.fail_status: raise self.fail_exception + # 打开搜索结果 + open_search_btn_element = self.browser_page.locator("div:text('条网页信息源')") + if await open_search_btn_element.count() > 0: + await open_search_btn_element.click() + # 获取回答元素 answer_element = self.browser_page.locator("//div[contains(@class, 'dialog-card-wrapper')]").nth(-1) box = await answer_element.bounding_box() logger.debug(f'answer_element: {box}') view_port_height = box['height'] + 1000 + # 调整视口大小 await self.browser_page.set_viewport_size({ 'width': 1920, 'height': int(view_port_height) }) - # 打开搜索结果 - open_search_btn_element = self.browser_page.locator("div:text('条网页信息源')") - if await open_search_btn_element.count() > 0: - await open_search_btn_element.click() + + await asyncio.sleep(2) # 截图 screenshot_path = self._get_screenshot_path() await self.browser_page.screenshot(path=screenshot_path) diff --git a/spiders/ai_seo/yuanbao.py b/spiders/ai_seo/yuanbao.py index 9fd146a..75d23f6 100644 --- a/spiders/ai_seo/yuanbao.py +++ b/spiders/ai_seo/yuanbao.py @@ -63,22 +63,25 @@ class YuanBaoSpider(AbstractAiSeoSpider): if self.fail_status: raise self.fail_exception - # # 获取回答元素 + # 打开联网搜索结果 + search_list_element = self.browser_page.locator("(//div[contains(@data-title, '资料作为参考')])[1]/span") + if await search_list_element.is_visible(): + await search_list_element.click() + + # 获取回答元素 answer_element = self.browser_page.locator("//div[@class='agent-chat__list__item__content']").nth(-1) box = await answer_element.bounding_box() logger.debug(f'answer_element: {box}') view_port_height = box['height'] + 500 - # # 调整视口大小 + # 调整视口大小 await self.browser_page.set_viewport_size({ 'width': 1920, 'height': int(view_port_height) }) # 收起侧栏 # await self.browser_page.locator("//div[@data-desc='fold']").click() - # 打开联网搜索结果 - search_list_element = self.browser_page.locator("(//div[contains(@data-title, '资料作为参考')])[1]/span") - if await search_list_element.is_visible(): - await search_list_element.click() + await asyncio.sleep(2) + # 截图 screenshot_path = self._get_screenshot_path() await self.browser_page.screenshot(path=screenshot_path)