Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

node的phantomjs #40

Open
Wscats opened this issue Jun 26, 2018 · 0 comments
Open

node的phantomjs #40

Wscats opened this issue Jun 26, 2018 · 0 comments

Comments

@Wscats
Copy link
Owner

Wscats commented Jun 26, 2018

安装

去官网下载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);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant