My main goal is to save pandas dataframe with html and scc styles as image. I’m having problems imgkit so I tried html2image. And it worked for me. But a few days later the same code doesn’t do anything. No error either. I even created a new venv with html2imageonly and ran simple code from other examples
from html2image import Html2Image
hti = Html2Image()
html = '<h1> A title </h1> Some text.'
css = 'body {background: red;}'
# screenshot an HTML string (css is optional)
hti.screenshot(html_str=html, css_str=css, save_as='page.png')
However, it doesn’t save anything, and just finishes programm with "Process finished with exit code 0".
I also tried looking in Temphtml2image and only found file from when the pachage was working.
Tried downgrading to 2.0.4, still no results.
First version of code looked like this
html = s.set_td_classes(cell_color).to_html()
root = get_project_root()
image_path = pathlib.Path(root, 'resources')
hti = Html2Image(output_path=image_path)
image_name = 'top_5_table.png'
hti.screenshot(html_str=html, css_str=CSS, save_as=image_name)
And it stopped working. I’ve tried removing css_str, changing output_path, still no result
I’m trying all of the versions, 1.1.3 and 2.0.3 at least save html files, not png, and to Temphtml2image
2
Answers
The Chrome Driver may need to be properly configured.
Based on this document, install the Chrome Driver that matches your environment.
brew install --cask chromedriver
sudo apt-get install chromium-driver
choco install chromedriver
Also based on the document, get the Chrome Driver
executable_path
according to your operating system./usr/bin/google-chrome
/Applications/Google Chrome.app/Contents/MacOS/Google Chrome
C:Users%USERNAME%AppDataLocalGoogleChromeApplicationchrome.exe
However, it’s might be a little different in practical situation. Dig into the similar folder and find the actual chromedriver.
In my case, it’s named as
/usr/bin/chromedriver
.Enter the
executable_path
path found above or specify the browser type.There has recently been updates to Chromium which are causing this problem. It appears to affect both Chrome and Edge browser based on Chromium version 128.0.x.x and higher. There is no resolution at this point other than downgrading the browser version. This GitHub issue has been created to track the problem.