linux安裝phantomjs


一.下載PhantomJS;

  從官網http://phantomjs.org/download.html下載linux64位的安裝包即  phantomjs-2.1.1-linux-x86_64.tar.bz2

     #tar -xjvf phantomjs-1.9.7-linux-x86_64.tar.bz2

       如果報沒找到命令,則yum install -y bzip2

      如果鏡像下載不下來,也可本地用360解壓好,直接上傳到服務器

     或者鏡像命令一直不行,考慮重啟鏡像

    yum clean all

  rpm --rebuilddb

安裝依賴——fontconfig和freetype: 

 #yum install fontconfig freetype2

將可執行文件放入系統路徑: 

 #sudo ln -s /usr/soft/phantomjs-2.1.1-linux-x86_64/bin/phantomjs /usr/local/bin/phantomjs

 

添加權限

sudo chmod u+x,o+x  /usr/soft/phantomjs-2.1.1-linux-x86_64/bin/phantomjs
如果還是不行,可以考慮加入環境變量中,修改etc/profile文件

在終端下測試Phantomjs。你應該會看到如下輸出:

 #phantomjs -v

1.9.7

 #cd /root/bin/phantomjs-1.9.7-linux-x86_64/bin

新建腳本,並確認截圖是否OK:

 #vi a.js

var page = require('webpage').create();
page.open('https://www.baidu.com/', function () {
page.render('test/example.png');
phantom.exit();
});

保存后進行截圖測試 

 #phantomjs a.js

完成后會出現一個test文件夾,在文件夾內有個圖片

查看圖片,顯示亂碼。

解決方案,安裝字體。

 #yum install bitmap-fonts bitmap-fonts-cjk

再次執行截圖

 #phantomjs a.js

查看圖片,字體顯示正常。

 

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM