fix: 直接对iframe内容进行full_page截图
使用iframe.screenshot(full_page=True)来截取iframe内的完整内容。 🤖 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,49 +1361,18 @@ class PlaywrightAutomation:
|
|||||||
# 先保存到临时文件
|
# 先保存到临时文件
|
||||||
temp_filepath = filepath + '.tmp'
|
temp_filepath = filepath + '.tmp'
|
||||||
|
|
||||||
# 展开所有可滚动容器,使内容完全显示
|
# 获取iframe并截取其完整内容
|
||||||
try:
|
iframe = self.get_iframe_safe()
|
||||||
self.main_page.evaluate("""() => {
|
if iframe:
|
||||||
// 移除body和html的高度限制
|
# 对iframe内容进行全页截图
|
||||||
document.documentElement.style.height = 'auto';
|
iframe.screenshot(
|
||||||
document.documentElement.style.overflow = 'visible';
|
path=temp_filepath,
|
||||||
document.body.style.height = 'auto';
|
type='jpeg',
|
||||||
document.body.style.overflow = 'visible';
|
full_page=True,
|
||||||
|
quality=100
|
||||||
// 查找所有可能的滚动容器并展开
|
)
|
||||||
const expandScrollable = (el) => {
|
else:
|
||||||
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(
|
self.main_page.screenshot(
|
||||||
path=temp_filepath,
|
path=temp_filepath,
|
||||||
type='jpeg',
|
type='jpeg',
|
||||||
|
|||||||
Reference in New Issue
Block a user