Browse Source

Merge remote-tracking branch 'origin/master'

master
zhurunlin 4 months ago
parent
commit
2d84ce2859
  1. 10
      .gitignore
  2. 12
      spiders/ai_seo/yiyan.py
  3. 15
      spiders/ai_seo/yuanbao.py

10
.gitignore

@ -0,0 +1,10 @@
data
.idea
.vscode
.venv
venv
config.py
screenshot
Pipfile
Pipfile.lock
logs

12
spiders/ai_seo/yiyan.py

@ -63,20 +63,24 @@ class YiYanSpider(AbstractAiSeoSpider):
if self.fail_status: if self.fail_status:
raise self.fail_exception 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) answer_element = self.browser_page.locator("//div[contains(@class, 'dialog-card-wrapper')]").nth(-1)
box = await answer_element.bounding_box() box = await answer_element.bounding_box()
logger.debug(f'answer_element: {box}') logger.debug(f'answer_element: {box}')
view_port_height = box['height'] + 1000 view_port_height = box['height'] + 1000
# 调整视口大小 # 调整视口大小
await self.browser_page.set_viewport_size({ await self.browser_page.set_viewport_size({
'width': 1920, 'width': 1920,
'height': int(view_port_height) '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() screenshot_path = self._get_screenshot_path()
await self.browser_page.screenshot(path=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: if self.fail_status:
raise self.fail_exception 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) answer_element = self.browser_page.locator("//div[@class='agent-chat__list__item__content']").nth(-1)
box = await answer_element.bounding_box() box = await answer_element.bounding_box()
logger.debug(f'answer_element: {box}') logger.debug(f'answer_element: {box}')
view_port_height = box['height'] + 500 view_port_height = box['height'] + 500
# # 调整视口大小
# 调整视口大小
await self.browser_page.set_viewport_size({ await self.browser_page.set_viewport_size({
'width': 1920, 'width': 1920,
'height': int(view_port_height) 'height': int(view_port_height)
}) })
# 收起侧栏 # 收起侧栏
# await self.browser_page.locator("//div[@data-desc='fold']").click() # 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() screenshot_path = self._get_screenshot_path()
await self.browser_page.screenshot(path=screenshot_path) await self.browser_page.screenshot(path=screenshot_path)

Loading…
Cancel
Save