fix: 改进截图逻辑,直接截取表格元素
尝试截取table.ltable元素来获取完整内容,而不是依赖full_page参数。 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -1361,16 +1361,35 @@ class PlaywrightAutomation:
|
|||||||
# 先保存到临时文件
|
# 先保存到临时文件
|
||||||
temp_filepath = filepath + '.tmp'
|
temp_filepath = filepath + '.tmp'
|
||||||
|
|
||||||
# 获取iframe并截取完整内容
|
# 获取iframe
|
||||||
iframe = self.get_iframe_safe()
|
iframe = self.get_iframe_safe()
|
||||||
if iframe:
|
if iframe:
|
||||||
# 对iframe内容进行全页截图
|
# 尝试截取iframe内的主要内容区域
|
||||||
iframe.screenshot(
|
try:
|
||||||
path=temp_filepath,
|
# 查找内容表格
|
||||||
type='jpeg',
|
table_locator = iframe.locator("table.ltable")
|
||||||
full_page=True,
|
if table_locator.count() > 0:
|
||||||
quality=100
|
table_locator.first.screenshot(
|
||||||
)
|
path=temp_filepath,
|
||||||
|
type='jpeg',
|
||||||
|
quality=100
|
||||||
|
)
|
||||||
|
else:
|
||||||
|
# 如果没有表格,截取整个body内容
|
||||||
|
iframe.locator("body").screenshot(
|
||||||
|
path=temp_filepath,
|
||||||
|
type='jpeg',
|
||||||
|
quality=100
|
||||||
|
)
|
||||||
|
except Exception as e:
|
||||||
|
self.log(f"元素截图失败: {e},尝试全页截图")
|
||||||
|
# 回退到iframe全页截图
|
||||||
|
iframe.screenshot(
|
||||||
|
path=temp_filepath,
|
||||||
|
type='jpeg',
|
||||||
|
full_page=True,
|
||||||
|
quality=100
|
||||||
|
)
|
||||||
else:
|
else:
|
||||||
# 如果无法获取iframe,回退到主页面截图
|
# 如果无法获取iframe,回退到主页面截图
|
||||||
self.main_page.screenshot(
|
self.main_page.screenshot(
|
||||||
|
|||||||
Reference in New Issue
Block a user