pyecharts渲染圖片

這篇文章講的是mac下的chromedriver和selenium安裝。 

各位同學在上手學習pyecharts時會有將網頁上的圖片渲染到本地的需求,如以下官方代碼:

from pyecharts.charts import Bar
from pyecharts import options as opts
from pyecharts.render import make_snapshot
from snapshot_selenium import snapshot

bar = (
    Bar()
    .add_xaxis(["襯衫", "羊毛衫", "雪紡衫", "褲子", "高跟鞋", "襪子"])
    .add_yaxis("商家A", [5, 20, 36, 10, 75, 90])
)
make_snapshot(snapshot, bar.render(), "bar.png")

直接執行會報以下錯誤: 

selenium.common.exceptions.WebDriverException: Message: 'chromedriver' executable needs to be in PATH. Please see https://sites.google.com/a/chromium.org/chromedriver/home

提示需要安裝selenium和chromedriver,安裝selenium很簡單,直接pip install即可。

然後安裝chromedriver會有一些問題,比如說用homebrew安裝會出現以下提示:

按照提示輸入:

brew tap homebrew/cask

brew cask install chromedriver

同樣的,也可以自己手動下載chromedriver然後放到 /usr/local/bin下

首先查看自己chrome瀏覽器的版本:

然後去http://npm.taobao.org/mirrors/chromedriver/

或者http://chromedriver.storage.googleapis.com/index.html

找到和自己chrome匹配的chromedriver。

然後將壓縮包解壓,解壓出來的chromedriver移動到/usr/local/bin目錄下即可。

最後就可以將html上的圖片渲染到本地啦。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章