Tag: 幻像

如何通过链接进行循环,并为PhantomJS中的每个站点执行jQuery javascript

我试图build立一个响应式网页devisetesting工具。 我已经成功地捕获了不同设备特定视口大小的链接数组中的每个链接。 但是该工具的另外一个要求是能够将自定义的JavaScript脚本注入到该站点中,等待该脚本完成,然后捕获该页面的状态(例如,有人希望在捕获它之前打开引导模式)。 我一直在使用jQueryGo Node模块来完成我的工作。 到目前为止我已经完成了 我已经设法使其工作,但不能够使用jQuery组件(和我曾尝试使用phantom提供的injectJs和includeJs)。 在下面的代码中使用asyncjs和一些辅助函数。 var $ = require('../node_modules/jquerygo/lib/jquery.go.js'); var async = require('../node_modules/jquerygo/node_modules/async/lib/async.js'); var jqueryCdn = 'http://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js'; var links = [{ url: "http://google.com", sitename: "Google", jsinject: function() { var log = document.querySelectorAll('title')[0].innerText; console.log(log); } }, … ]; var sizes = [{ device: "desktop", userAgent: "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like […]

node-horsemanasynchronous不起作用?

我正在使用node-horseman(希望)允许我执行asynchronousphantomjs操作来实现asynchronous无头浏览。 数组中的数字在这个阶段是不相关的,我只是将代码剥离到最低限度,以演示我遇到的问题。 当我运行下面的代码时,它运行asynchronous,但是,一旦我创build一个新的骑士,它将停止asynchronous运行。 我知道它没有运行asynchronous,因为输出(控制台logging数字)以线性方式发生,每个数字在统一的时间之后显示。 运行它asynchronous它应该是瞬间的,因为显示每一个的开销应该是相同的,所以所有的数字应该同时出现在他们没有创build骑马对象时的方式(如下面的代码对象禁用)。 var Horseman = require('node-horseman'); var async = require('async'); var testArray = [ 1, 2, 3, 4, 5 ]; function evaluate( item ) { console.log( item ); /*It runs asynchronously but if the two lines below are activated it stops being async and runs synchronously, defeating the whole purpose of using […]

脚本在Webstorm中失败,但不是从terminal

我有一个nodejs脚本,它使用phantomjs-node来抓取一个网页。 当我从terminal窗口运行时,它工作正常,但是当我通过Node JS应用程序的运行configuration从Webstorm内部运行时,它工作正常。 什么可能导致Webstorm中的错误? 我已经尝试在注释掉.bash_profile的内容之后从terminal运行脚本,它仍然有效。 我也在另一个示例脚本中检查了process.env的内容,发现Webstorm和terminal的值完全不同。 剧本: var phantom = require('phantom'); phantom.create(function(ph) { return ph.createPage(function(page) { return page.open("http://www.google.com", function(status) { console.log("opened google? ", status); return page.evaluate((function() { return document.title; }), function(result) { console.log('Page title is ' + result); return ph.exit(); }); }); }); }); terminal输出(伟大的工程!): opened google? success Page title is Google Webstorm控制台输出(失败): /usr/local/bin/node phantom.js […]