From b408e78c74ea9028d35b41cc8dac67750e8b3795 Mon Sep 17 00:00:00 2001 From: yuyx <237899745@qq.com> Date: Sun, 14 Dec 2025 16:08:41 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E6=94=B9=E8=BF=9B=E6=88=AA=E5=9B=BE?= =?UTF-8?q?=E9=80=BB=E8=BE=91=EF=BC=8C=E7=9B=B4=E6=8E=A5=E6=88=AA=E5=8F=96?= =?UTF-8?q?=E8=A1=A8=E6=A0=BC=E5=85=83=E7=B4=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 尝试截取table.ltable元素来获取完整内容,而不是依赖full_page参数。 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 --- playwright_automation.py | 35 +++++++++++++++++++++++++++-------- 1 file changed, 27 insertions(+), 8 deletions(-) diff --git a/playwright_automation.py b/playwright_automation.py index 9831b8b..83460a5 100755 --- a/playwright_automation.py +++ b/playwright_automation.py @@ -1361,16 +1361,35 @@ class PlaywrightAutomation: # 先保存到临时文件 temp_filepath = filepath + '.tmp' - # 获取iframe并截取完整内容 + # 获取iframe iframe = self.get_iframe_safe() if iframe: - # 对iframe内容进行全页截图 - iframe.screenshot( - path=temp_filepath, - type='jpeg', - full_page=True, - quality=100 - ) + # 尝试截取iframe内的主要内容区域 + try: + # 查找内容表格 + table_locator = iframe.locator("table.ltable") + if table_locator.count() > 0: + 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: # 如果无法获取iframe,回退到主页面截图 self.main_page.screenshot(