Browse Source

修复元宝和文心一言平台截图问题

master
zzx 4 months ago
parent
commit
10922ec1d2
  1. 12
      spiders/ai_seo/yiyan.py
  2. 15
      spiders/ai_seo/yuanbao.py

12
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)

15
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)

Loading…
Cancel
Save