node-tutorial icon indicating copy to clipboard operation
node-tutorial copied to clipboard

node的phantomjs

Open Wscats opened this issue 7 years ago • 0 comments

安装

去官网下载phantomjs的压缩文件并安装

PhantomJS官方地址 PhantomJS官方API PhantomJS官方示例 PhantomJS GitHub

环境变量

打开我的电脑->右键属性->高级系统设置->高级标签->环境变量,在系统变量里找到Path将你的phantomjs添加到环境变量里。比方说我的路径添加的为D:\workspace\phantomjs\bin,切记不要少了前面那个分号

运行

可以开始我们的第一个PhantomJS程序了。打开你的工作目录,新建文件hello.js,敲入以下代码,phantomjs hello.js

// a phantomjs example
var page = require('webpage').create();
phantom.outputEncoding = "gbk";
page.open("http://www.cnblogs.com/front-Thinking", function(status) {
	if(status === "success") {
		console.log(page.title);
	} else {
		console.log("Page failed to load.");
	}
	phantom.exit(0);
});

Wscats avatar Jun 26 '18 09:06 Wscats