Splinter
支持对网页截图,对元素截图,以及保存html
文件。API传递的路径参数均需使用绝对路径。
browser = Browser()
browser.visit('http://example.com')
screenshot_path = browser.screenshot('absolute_path/your_screenshot.png')
应使用绝对路径保存屏幕截图。如果不使用绝对路径,屏幕快照将保存在一个临时文件中。
browser = Browser()
browser.visit('http://example.com')
screenshot_path = browser.screenshot('absolute_path/your_screenshot.png', full=True)
使用元素截图,首先需要安装Pillow:
pip install Pillow
如果元素位于当前窗口:
browser = Browser()
browser.visit('http://example.com')
screenshot_path = browser.find_by_xpath('xpath_rule').first.screenshot('absolute_path/your_screenshot.png')
如果元素不位于当前窗口:
browser = Browser()
browser.visit('http://example.com')
screenshot_path = browser.find_by_xpath('xpath_rule').first.screenshot('absolute_path/your_screenshot.png', full=True)
Take html snapshot操作实际上会读取html文件,并保存到本地,这里保存的并不是图片,而是html
的源码。
browser = Browser()
screenshot_path = browser.html_snapshot('absolute_path/your_screenshot.html')
版权声明:本站所有资料均为网友推荐收集整理而来,仅供学习和研究交流使用。
工作时间:8:00-18:00
客服电话
电子邮件
admin@qq.com
扫码二维码
获取最新动态