安装包
pip install html2image
转换本地html文件
from html2image import Html2Image
hti = Html2Image()
hti.screenshot(other_file='测试.html', save_as='测试.png')
转换url
from html2image import Html2Image
hti = Html2Image()
hti.screenshot(url='https://www.baidu.com/', save_as='baidu.png')
设置图片大小
from html2image import Html2Image
hti = Html2Image()
hti.screenshot(url='https://www.baidu.com/', save_as='baidu.png', size= (1000,1000))
更多参考
I wrote a Python package that lets you generate images from HTML/CSS strings or files and URLs
html2image