2

I am trying to export a map I have made with folium in Python to a png format. According to the post below, this can be made with selenium and the following command:

Export a folium map as a png

import io
from PIL import Image
import selenium 

img_data = map._to_png(5)
img = Image.open(io.BytesIO(img_data))
img.save('map_folium.png')

But I end up with the error:

TimeoutException: Message: Connection refused (os error 111)

In the help forums I have consulted to fix this error mention a problem with firefox not in path. But it is the case on my system. Has anyone encountered the same issue?

1 Answers1

1

Eventually, I have used another webdriver than Firefox to output the map:

import folium
from selenium import webdriver
import os
import time
import selenium

mapFname = 'folium_map.html'
mapUrl = 'file://{1}'.format(os.getcwd(), mapFname)

# use selenium to save the html as png image
driver = webdriver.Firefox(firefox_binary = "path/to/waterfox")
driver.get(mapUrl)

# wait for 5 seconds for the maps and other assets to be loaded in the browser
time.sleep(5)
driver.save_screenshot('output.png')
driver.quit()