phantomjs安装使用

来源:互联网 发布:如何mac安装eclipse 编辑:程序博客网 时间:2024/05/16 15:03

phantomjs安装

phantomjs 是一款基于webkit的无界面浏览器,提供多种js api;可以方便的进行扩展:

yum --skip-broken install fontconfig freetype libfreetype.so.6 libfontconfig.so.1 wget https://bitbucket.org/ariya/phantomjs/downloads/phantomjs-1.9.7-linux-x86_64.tar.bz2tar jxvf phantomjs-1.9.7-linux-x86_64.tar.bz2mv phantomjs-1.9.7-linux-x86_64 phantomjscd phantomjs

测试网页加载渲染速度:

./bin/phantomjs examples/loadspeed.js http://www.58game.com

抓取网页下载过程请求,类似于httpfox:

./bin/phantomjs examples/netsniff.js http://www.58game.com

网页截图:

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

保存为t.js,执行

先给phantomjs执行权限 chmod u+x phantomjs

./bin/phantomjs /root/t.js
0 0
原创粉丝点击