【发布时间】:2015-08-11 10:50:48
【问题描述】:
这是我的代码:
<html>
<body>
<script src="bin/phantomjs"></script>
<script src="js/test.js"></script>
</body>
</html>
在 test.js 中
var page = require('webpage').create();
console.log('The default user agent is ' + page.settings.userAgent);
page.settings.userAgent = 'SpecialAgent';
page.open('http://www.httpuseragent.org', function (status) {
if (status !== 'success') {
console.log('Unable to access network');
} else {
var ua = page.evaluate(function () {
return document.getElementById('myagent').innerText;
});
console.log(ua);
}
phantom.exit();
});
使用 Chrome 查看时出现这些错误。
Uncaught SyntaxError: Unexpected token ILLEGAL
test.js:1 Uncaught ReferenceError: require is not defined
我想在我的 html 项目中加载 PhantomJS,这样我就可以开始抓取网站了。
【问题讨论】:
标签: javascript browser phantomjs