stone_0625 2021-03-16 16:55 采纳率: 0%
浏览 548

python中imgkit和wkhtmltoimage 与xvfb的坑

刚刚想做一个图片,发现这个问题

import imgkit
html = imgkit.from_url(url="https://www.baidu.com",output_path="out.png")

运行后发现报这个错

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "D:/EJU/dealspiders/qiyewecat/demo3.py", line 7, in <module>
    html = imgkit.from_url(url="https://www.baidu.com",output_path="out.png")
  File "C:\Users\EJU\AppData\Local\Programs\Python\Python36\lib\site-packages\imgkit\api.py", line 31, in from_url
    cover_first=cover_first)
  File "C:\Users\EJU\AppData\Local\Programs\Python\Python36\lib\site-packages\imgkit\imgkit.py", line 34, in __init__
    self.config = Config() if not config else config
  File "C:\Users\EJU\AppData\Local\Programs\Python\Python36\lib\site-packages\imgkit\config.py", line 36, in __init__
    'http://wkhtmltopdf.org\n'.format(self.wkhtmltoimage))
OSError: No wkhtmltoimage executable found: "b''"
If this file exists please check that this process can read it. Otherwise please install wkhtmltopdf - http://wkhtmltopdf.org

一番找解决方式后,把代码改成了

import imgkit
path_wk = r"E:\\software\\wkhtmltopdf\\bin\\wkhtmltoimage.exe"
config = imgkit.config(wkhtmltoimage=path_wk)
html = imgkit.from_url(url="https://www.baidu.com",config=config,output_path="out.png")

然后wkhtmltoimage不报错了,但是xvfb却依然过不去

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "D:/EJU/dealspiders/qiyewecat/demo2.py", line 14, in <module>
    config = imgkit.config(wkhtmltoimage=path_wk)
  File "C:\Users\EJU\AppData\Local\Programs\Python\Python36\lib\site-packages\imgkit\api.py", line 101, in config
    return Config(**kwargs)
  File "C:\Users\EJU\AppData\Local\Programs\Python\Python36\lib\site-packages\imgkit\config.py", line 44, in __init__
    'read it. Otherwise please install xvfb -'.format(self.xvfb))
OSError: No xvfb executable found: "b''"
If this file exists please check that this process can read it. Otherwise please install xvfb -

求大神指点

  • 写回答

1条回答 默认 最新

  • weishaoonly 2023-07-18 17:06
    关注
    import imgkit
    
    path_wk = r"E:\\software\\wkhtmltopdf\\bin\\wkhtmltopdf.exe"
    config = imgkit.config(wkhtmltopdf=path_wk)
    html = imgkit.from_url(url="https://www.baidu.com", config=config, output_path="out.png")
    
    评论

报告相同问题?

悬赏问题

  • ¥15 #MATLAB仿真#车辆换道路径规划
  • ¥15 java 操作 elasticsearch 8.1 实现 索引的重建
  • ¥15 数据可视化Python
  • ¥15 要给毕业设计添加扫码登录的功能!!有偿
  • ¥15 kafka 分区副本增加会导致消息丢失或者不可用吗?
  • ¥15 微信公众号自制会员卡没有收款渠道啊
  • ¥100 Jenkins自动化部署—悬赏100元
  • ¥15 关于#python#的问题:求帮写python代码
  • ¥20 MATLAB画图图形出现上下震荡的线条
  • ¥15 关于#windows#的问题:怎么用WIN 11系统的电脑 克隆WIN NT3.51-4.0系统的硬盘