diff --git a/playwright_automation.py b/playwright_automation.py index a547eb0..610820e 100755 --- a/playwright_automation.py +++ b/playwright_automation.py @@ -1361,55 +1361,24 @@ class PlaywrightAutomation: # 先保存到临时文件 temp_filepath = filepath + '.tmp' - # 展开所有可滚动容器,使内容完全显示 - try: - self.main_page.evaluate("""() => { - // 移除body和html的高度限制 - document.documentElement.style.height = 'auto'; - document.documentElement.style.overflow = 'visible'; - document.body.style.height = 'auto'; - document.body.style.overflow = 'visible'; - - // 查找所有可能的滚动容器并展开 - const expandScrollable = (el) => { - if (!el || el === document.documentElement) return; - const style = window.getComputedStyle(el); - if (style.overflow === 'auto' || style.overflow === 'scroll' || - style.overflowY === 'auto' || style.overflowY === 'scroll') { - el.style.height = 'auto'; - el.style.maxHeight = 'none'; - el.style.overflow = 'visible'; - } - if (el.parentElement) expandScrollable(el.parentElement); - }; - - // 从表格开始向上展开 - const table = document.querySelector('table.ltable, .ltable, table'); - if (table) expandScrollable(table.parentElement); - - // 展开所有带overflow的元素 - document.querySelectorAll('*').forEach(el => { - const style = window.getComputedStyle(el); - if ((style.overflow === 'auto' || style.overflow === 'scroll' || - style.overflowY === 'auto' || style.overflowY === 'scroll') && - el.scrollHeight > el.clientHeight) { - el.style.height = el.scrollHeight + 'px'; - el.style.maxHeight = 'none'; - el.style.overflow = 'visible'; - } - }); - }""") - time.sleep(0.5) - except Exception: - pass - - # 截取整个页面 - self.main_page.screenshot( - path=temp_filepath, - type='jpeg', - full_page=True, - quality=100 - ) + # 获取iframe并截取其完整内容 + iframe = self.get_iframe_safe() + if iframe: + # 对iframe内容进行全页截图 + iframe.screenshot( + path=temp_filepath, + type='jpeg', + full_page=True, + quality=100 + ) + else: + # 回退到主页面截图 + self.main_page.screenshot( + path=temp_filepath, + type='jpeg', + full_page=True, + quality=100 + ) # 验证文件是否成功创建且大小合理 if not os.path.exists(temp_filepath):