pyecharts+snapshot_selenium的方式只能将图表转为图片,html中的其他元素会被忽略,几番查找后发现imgkit效果还可以(win10和centos7测试OK)
首先需安装imgkit工具:https://wkhtmltopdf.org/downloads.html
下载对应系统的包安装
linux下若有依赖包缺失可在此下载:https://pkgs.org/
pip install imgkit
import os
import platform
import imgkit
imgkit_cfg = None
if platform.system() == "Windows":
# 未加环境变量时需指定路径
path_wkimg = r"D:\Programs\wkhtmltopdf\bin\wkhtmltoimage.exe"
imgkit_cfg = imgkit.config(wkhtmltoimage=path_wkimg)
else:
imgkit_cfg = imgkit.config()
imgkit_options = {"encoding": "UTF-8"}
# 1、将html文件转为图片
imgkit.from_file(
"1111.html", "helloworld.png", options=imgkit_options, config=imgkit_cfg
)
# 2、从url获取html,再转为图片
imgkit.from_url("https://www.baidu.com", "hello.jpg", config=imgkit_cfg)
# 3、将字符串转为图片
imgkit.from_string("Hello!", "hello.jpg", config=imgkit_cfg)
https://blog.csdn.net/BobYuan888/article/details/108769274
评论区