【发布时间】:2021-03-17 05:50:32
【问题描述】:
我正在尝试保存包含标记和热图的地图。
这是显示地图的代码。
import folium
m_f = folium.Map(location= [39.76258, 254.994682],
zoom_start=8)
m_f.save('f_map.html')
m_f
然后我使用 phantomjs 保存图像。
import selenium.webdriver
import time
from selenium import webdriver
driver = webdriver.PhantomJS(executable_path='/Users/path/Downloads/PhantomJS/bin/phantomjs')
driver.set_window_size(4000, 3000) # choose a resolution
driver.get('f_map.html')
# You may need to add time.sleep(seconds) here
time.sleep(1)
driver.save_screenshot('f_map.png')
到这里为止没有问题。
但是,当我在地图上添加一些标记时,我得到了正确的 html 文件,我也可以在浏览器中打开它,但它的屏幕截图是一个空白文件(内容)。
这是新地图的代码
import folium
m_f = folium.Map(location= [39.74258, 254.993682],
zoom_start=12)
arr_test1 = [39.74258, 254.993682]
arr_test2 = [39.75258, 254.994682]
arr_test3 = [39.76258, 254.994682]
all_loc = [arr_test1, arr_test2, arr_test3]
for cur_loc in all_loc:
point = folium.Circle(
radius=200,
location=cur_loc,
popup='The Waterfront',
color='red',
fill=False,
)
point.add_to(m_f)
time.sleep(0.001)
m_f
m_f.save('f_map_marker.html')
及其phantonjs代码行
import selenium.webdriver
import time
from selenium import webdriver
driver = webdriver.PhantomJS(executable_path='/Users/path/Downloads/PhantomJS/bin/phantomjs')
driver.set_window_size(4000, 3000) # choose a resolution
driver.get('f_map_marker.html')
time.sleep(1)
driver.save_screenshot('f_map_marker.png')
所以,f_map_marker.png 文件是空白的。
有谁知道,为什么会这样,以及我该如何解决这个问题?
欢迎任何提示。
【问题讨论】:
标签: python dictionary selenium-webdriver phantomjs folium