python playwright 没看见有clip参数啊
Python Playwright 的 Page 类中确实没有 clip 参数,但是可以使用 Page.screenshot() 方法的 clip 参数来裁剪截图。
例如,以下代码会在页面上选择一个元素并截取其可见部分:
from playwright.sync_api import Playwright, sync_playwright
with sync_playwright() as playwright:
browser = playwright.chromium.launch()
page = browser.new_page()
page.goto('https://example.com')
element_handle = page.locator('h1')
screenshot_buffer = element_handle.screenshot(clip=element_handle.bounding_box())
with open('screenshot.png', 'wb') as f:
f.write(screenshot_buffer)
browser.close()
其中,element_handle.bounding_box() 返回元素的边界框,element_handle.screenshot() 方法使用 clip 参数来裁剪截图
原文地址: https://www.cveoy.top/t/topic/hkx1 著作权归作者所有。请勿转载和采集!