我想在我的node.js脚本中使用phantomjs.有一个phantomjs节点库..但不幸的是,作者使用这个奇怪的咖啡脚本代码来解释他在做什么:
phantom = require 'phantom'
phantom.create (ph) ->
ph.createPage (page) ->
page.open "http://www.google.com", (status) ->
console.log "opened google? ", status
page.evaluate (-> document.title), (result) ->
console.log 'Page title is ' + result
ph.exit()
Run Code Online (Sandbox Code Playgroud)
现在如果我直接用javascript使用phantomjs,它看起来像这样:
var page = require('webpage').create();
page.open(url, function (status) {
var title = page.evaluate(function () {
return document.title;
});
console.log('Page title is ' + title);
});
Run Code Online (Sandbox Code Playgroud)
所以基本上我正在尝试在普通的javascript中编写相当于上面第一段代码的代码(通过阅读咖啡脚本文档 ..这就是我所做的:
// file name: phantomTest.js
var phantom = require('phantom');
phantom.create(function(ph) {
ph.createPage(function(page) {
page.open('http://www.google.com', function(status) { …Run Code Online (Sandbox Code Playgroud)