|
|
|
@ -47,10 +47,24 @@ class NanometerSpider(AbstractAiSeoSpider): |
|
|
|
raise self.fail_exception |
|
|
|
|
|
|
|
# 获取回答元素 |
|
|
|
# answer_element = self.browser_page.locator("//div[@id='search-list']") |
|
|
|
box = await self.browser_page.evaluate("() => document.body.scrollHeight") |
|
|
|
logger.debug(f'answer_element: {box}') |
|
|
|
view_port_height = box+ 500 |
|
|
|
# # answer_element = self.browser_page.locator("//div[@id='search-list']") |
|
|
|
# frame = self.browser_page.frame_locator("//div[@class='size-full']") |
|
|
|
# # height = await frame.locator("//div[@id='search-list']").bounding_box() |
|
|
|
# height = await frame.evaluate("() => document.body.scrollHeight") |
|
|
|
# 获取 iframe 元素的 bounding box,包含 width 和 height |
|
|
|
iframe_locator = self.browser_page.frame_locator("iframe[src='https://so.n.cn/bot-iframe?src=bot_search']") |
|
|
|
# 进入第一个匹配的 iframe(若存在多个,需指定索引或更具体的选择器) |
|
|
|
iframe =iframe_locator |
|
|
|
# 定位 iframe 内的 div 元素 |
|
|
|
div_locator = iframe.locator("//div[@class='flex flex-col gap-8px']") |
|
|
|
|
|
|
|
# 获取 div 元素的 bounding box,包含 width 和 height |
|
|
|
div_box = await div_locator.bounding_box() |
|
|
|
# 提取宽高信息 |
|
|
|
div_width = div_box['width'] if div_box else None |
|
|
|
div_height = div_box['height'] if div_box else None |
|
|
|
logger.debug(f'answer_element: {div_height}') |
|
|
|
view_port_height = div_box['height']+ 500 |
|
|
|
# 调整视口大小 |
|
|
|
await self.browser_page.set_viewport_size({ |
|
|
|
'width': 1920, |
|
|
|
|