Tag: phantomjs

无法让page.injectJs()在PhantomJS中工作

我在我的代码中有以下内容: phantom.createPage(function(page){ page.onCallback = function(data) { console.log("ph callback: ", data); }; page.open(req.query.testUrl, function(status){ if(status !== 'success'){ page.close(); res.status(500) .send('Page "' + testUrl + '" could not be loaded.') .end(); return; } var result = page.injectJs('lib/my-test-script.js'); console.log('injectJS: ', result); page.evaluate(function(){ window.callPhantom(window.mocha.constructor.name); }, function(){ console.log('finished'); page.close(); res.json({status: status}); res.end(); }); }); }); 和console.log('injectJS: ', result); 正在输出“injectJS:undefined”,而不是显式false因为文档在这里说: http://phantomjs.org/api/webpage/method/inject-js.html […]

窗户上的幻影

我有以下非常简单的代码: var phantom = require('phantomjs'); phantom.create(function(ph){ ph.createPage(function(page) { page.open("http://www.google.com", function(status) { page.render('google.pdf', function(){ console.log('Page Rendered'); ph.exit(); }); }); }); }); 当我运行这个我得到一个undefined is not a function错误在线phantom.create() 我现在坐在一台Windows机器上,并阅读的地方,我可能不得不使用的东西叫dnode我的问题是这可能是错误的原因,或者在代码中可能是错误的东西吗? 更新 我已经将var phantom = requiere(phantomjs)更改为var phantom = requiere(phantom) ,但现在我得到错误: phantom stderr: 'phantomjs' is not recognised as an internal or external kommand, a program or a batchfil. … AssertionError: abnormal […]

带有MongoDB NPM模块的CasperJS

我正在运行CasperJS 1.1.0-DEV,并要求mongoskin NPM模块将文档插入到Mongodb中。 但是使用mongoskin NPM模块 var mongo = require('mongoskin') var db = mongo.db('mongodb://localhost:27017/test', {native_parser: true})') 抛出错误 ReferenceError: Can't find variable: process /Users/username/casper-test/node_modules/mongoskin/index.js:1 /Users/username/casper-test/node_modules/mongoskin/index.js:2 TypeError: 'undefined' is not a function (evaluating 'mongo.db('mongodb://localhost:27017/test', {native_parser: true})') test.js:3 应该如何正确的使用CasperJS和mongoskin这样的NPM模块?

如何在PhantomJS中使用jQuery循环表格行

我试图学习一些networking与node.js刮。 我select了一些示例页面,例如http://www.imdb.com/chart/top 。 然后我试图用评分来刮掉所有的标题。 我创build了一个PhantomJS脚本(我需要使用它,因为它是dynamic的,所以它使用JavaScript上的网站)。 它的工作,但我不知道如何为每个标题循环。 例如: $('.lister-list tr').each( function(){ $(this).find('.titleColumn').text().replace(/\n/g, ''); $(this).find('.imdbRating').text().replace(/\n/g, ''); } ); 然后我把它放在一个JSON文件中。 在这一刻,我只能把数据没有循环。 这是我的脚本: var phantom = require('phantom'); var fs = require('fs'); phantom.create(function (ph) { ph.createPage(function (page) { page.open("http://www.imdb.com/chart/top", function (status) { page.evaluate(function () { //search datajquer var k_title = $('.lister-list tr .titleColumn').first().text().replace(/\n/g, ''); var k_rating = $('.lister-list tr .imdbRating').first().text().replace(/\n/g, […]

在Node webkit上使用phantom

我试图通过使用Phantom来抓取Node webkit中的dynamic内容。 我也添加了phantomjs envvariables。 当我运行应用程序,我得到一个版本不匹配错误:“未捕获的错误:模块版本不匹配。预计43,得到46。 通过运行nw:版本我得到以下版本: nw.js v0.12.3 io.js v1.2.0 铬41.0.2272.76 我应该如何解决这个错误? 如果您能够使用其他软件包来实现类似的function,请告诉我。

是否有可能开始幻影2与产卵?

正如我们所知,phantomjs 2没有正式发布,是否有可能下载一个.exe并使用childProcess.spawn('./phantomjs midges.js)来运行phantomjs2,它通过exec运行,但不使用spawn时。 我试图避免使用exec,因为phantomjs过程返回大量的数据,在这种情况下使用exec是一个糟糕的做法,而且我不能运行多个幽灵的exec

检测node.js上的纯色图像

Iam使用phantomjs进行屏幕截图,但有时会失败并产生一个纯色的灰色图像。 我只是想testing一个图像是否只是一个纯色,如果它是一个testing失败。 什么将是一个非常简单而有效的testing方法呢?

使用PhantomJS和Travis CI运行实习生testing

语境: 我正在使用Intern框架运行一些unit testing。 由于我testing的代码是我在NPM上发布的一个包,我想将它与Travis CI集成。 在我的本地,所有的testing运行良好。 但是,使用Travis CI,testing因为启动PhantomJSnetworking服务器而停滞不前。 这是我的Travis CI文件: language: node_js node_js: – "4" env: – CXX=g++-4.8 addons: apt: sources: – ubuntu-toolchain-r-test packages: – g++-4.8 before_script: – bower install – npm install grunt-cli -g – grunt installation – phantomjs –webdriver=4444 因为phantomjs命令启动了一个web服务器,所以它永远不会运行npm test 。 它只是暂停在networking服务器上。 题: 启动PhantomJS后,如何进行npm test ? 有什么方法可以将该过程移到后台,还是启动另一个过程来运行我的testing? 还是有一种方式调用phantomjs –webddriver=444和intern-runner config=tests/intern在同一时间?

批量截图与幻影为nodejs

我拼命试图在一个镜头中处理200个截图,我的第一个尝试是遵循指导,用一个简单的脚本调用200次, phantom.create() .then(function(instance) { console.log("1 – instance") phInstance = instance; return instance.createPage(); }) .then(function(page) { console.log("2 – page") sitepage = page; return page.open(url); }) .then(function(status) { console.log("3 – render") sitepage.property('clipRect', {top: 0, left: 0, width:3000,height:890}).then(function() { sitepage.render(fname).then(function(finished) { console.log("\t\t\t—> finished"); sitepage.close(); phInstance.exit(); callback({msg: 'ok'}) phantom.exit(); return; }); }); }) 这个方法有点不错,但是对于cpu来说确实是压倒性的,问题与这样一个事实有关,这种做法导致200个幻影进程快速地消耗掉所有的内存。 一个更有利的方法是创build一个幻像实例,然后驱动它打开一个页面,然后渲染它,这可以用一个幻影脚本完成,如下所示: var content, counter, f, […]

如何使用horseman和nodejs打开一个URL数组?

我试图用骑士login到一个网站,find一组链接,打开每一个,刮一些数据,并返回它。 这是我到目前为止… function getLinks() { return horseman.evaluate(function () { var links = []; $('#cards > tbody > tr:not(:first-child) a').each(function (i, el) { links.push($(el).attr('href')); }); return links; }); } function scrapeDataFromLink(link) { return horseman .open(link) .waitForSelector('#details > fieldset > table') .evaluate(function () { var data = { name: $('#name > td:nth-child(2)').html().trim(), type: $('#type > td:nth-child(2)').html().trim(), expiry: […]