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(