Tag: phantomjs

使用PhantomJS进行性能testing

我正在使用Google大豆模板,并开发了服务器端和客户端的渲染解决scheme。 我想用性能testing来对它们进行基准testing。 在对客户端部分进行基准testing时,我想等待所有的javascript操作执行,以计算实际的响应时间。 我在下面尝试过,但是这并不能解决我的目的。 PhantomJS支持访问单个页面并查询页面上所需的信息,但是不提供任何选项来模拟并发连接 Nodeload提供了加载testing服务器的function,但是没有任何选项可以从页面中检索信息。 是否有其他的框架,我可以用来做负载testing以及页面抓取?

我如何在phantomjs中设置代理

这https://www.npmjs.com/package/phantom#functionality-details页面说: 您还可以通过指定其他参数phantom.create()将命令行开关传递给phantomjs进程,例如: phantom.create '–load-images=no', '–local-to-remote-url-access=yes', (page) -> 或者通过在选项*对象中指定它们: phantom.create {parameters: {'load-images': 'no', 'local-to-remote-url-access': 'yes'}}, (page) -> 这些例子只在咖啡脚本中,也暗示了创build函数可以采用 create('string',function) 要么 create([object object],function) 但真正的第一个参数是预期的function! 我真的想尝试http://phantomjs.org/api/command-line.html我可能有错误的想法,但对我来说,它看起来像他们可以用于创buildfunction(就在你做createPage之前),上午我错了? 我已经尝试了几件事情,最合乎逻辑的是: var phantom = require('phantom'); phantom.create(function(browser){ browser.createPage(function(page){ page.open('http://example.com/req.php', function() { });},{parameters:{'proxy':'98.239.198.83:21320'}});}); 所以页面被打开。 我知道这一点,因为我正在使req.php保存$ _SERVER对象到一个TXT垫,但是,REMOTE_ADDR和REMOTE_PORT头不是我已经设置的代理。 他们没有效果。 我也试过了: {options:{'proxy':'98.239.198.83:21320'}} 由于文档称这个对象的选项*对象*见上面^ 和 '–proxy=98.239.198.83:21320' 我也通过幻影模块挖掘find创buildfunction。 它不是写在JS我至less看不到它。 它必须在C ++中。 它看起来像这个模块已经更新,但模块内部的例子看起来像旧代码。 我该怎么做呢? 编辑: var phantom = require('phantom'); phantom.create(function(browser){ […]

通过exec将variables传递给PhantomJS

我开始使用Grunt,并希望将一个variables传递给我通过exec运行的PhantomJS脚本。 我希望能够做的是通过一个URL的脚本从屏幕捕获。 任何帮助将不胜感激,谢谢! 达伦 咕script脚本 exec('phantomjs screenshot.js', function (error, stdout, stderr) { // Handle output } ); screenshot.js var page = require('webpage').create(); page.open('http://google.com', function () { page.render('google.png'); phantom.exit(); });

我如何在phantomJS中执行jQuery的承诺?

我正在使用试图在服务器端使用nodejs和phantomjs来search我们的网站。 虽然AJAX工作正常,我不能执行我已经在我的代码中使用自定义的承诺。 如何让幻影等待承诺解决。 以下是我编码的内容。 $('body').addClass('before-dom-ready'); $(function() { $('body').addClass('after-dom-ready'); var dfrd = $.Deferred(), promise = dfrd.promise(); setTimeout(function() { dfrd.resolve(); }, 5000); promise.done(function() { $('body').addClass('promise-executed'); }); }); phantomJS增加了“准备就绪”和“准备就绪”的课程,但是我无法获得“承诺执行”的课程。

Phantomjs:某些页面无法打开

我目前正在编写一个涉及networking抓取的networking应用程序。 为了帮助,我正在使用phantomjs的帮助。 但是,某些(但不是全部)网页正在返回状态=“失败”。 这里是代码(注意:这实际上是使用node-phantom库在nodejs中编写的: https : //github.com/alexscheelmeyer/node-phantom 。虽然语法可能不同,但是这个库实际上直接与phantomjs一起工作所以它不应该做任何不同的事情: phantom.create(function (err,ph) { ph.createPage(function (err,page) { page.onResourceError = function(errorData) { console.log('Unable to load resource (URL:' + errorData.url + ')'); console.log('Error code: ' + errorData.errorCode + '. Description: ' + errorData.errorString); }; page.onLoadFinished = function(status) { console.log('Status: ' + status); if(status==='success') { page.includeJs('http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js', function () { if(fetch_results) { […]

警告:PhantomJS找不到

我在Debian 6上安装了nodejs 0.10.15。然后我安装了npm: sudo npm install grunt-cli -g 我也执行了npm install在我的本地testing目录(下载必要的依赖到node_modules目录),它包含下面的package.json文件: { "name": "sample-name", "version": "1.4.0", "devDependencies": { "grunt": "~0.4.1", "grunt-contrib-qunit": ">0.0.0", "grunt-qunit-istanbul": ">0.0.0" } } 这里是安装phantomjs时的输出: … Writing location.js file Done. Phantomjs binary available at /home/myuser/Test/node_modules/grunt-contrib-qunit/node_modules/grunt-lib-phantomjs/node_modules/phantomjs/lib/phantom/bin/phantomjs Done. Phantomjs binary available at /home/myuser/Test/node_modules/grunt-qunit-istanbul/node_modules/grunt-lib-phantomjs-istanbul/node_modules/phantomjs/lib/phantom/bin/phantomjs grunt@0.4.1 node_modules/grunt ├── which@1.0.5 … 但是当我从testing目录运行grunttesting时 ,我得到: Running PhantomJS…ERROR >> In order for […]

从PhantomJS传递一个值到node.js

我有一个phantomJS脚本,通过node.js脚本中的exec()调用执行。 现在我需要从PhantomJS脚本中返回一个string,以便它可以在节点中使用。 有没有办法做到这一点? 节点应用: child = exec('./phantomjs dumper.js', function (error, stdout, stderr) { console.log(stdout, stderr); // Always empty }); dumper.js(幻影) var system = require('system'); var page = require('webpage').create(); page.open( system.args[1], function (status) { if (status !== 'success') { console.log('Unable to access the network!'); } else { return "String"; // Doesn't work } phantom.exit('String2'); //Doesn't work […]

如何获得casper.js http.status代码?

我有以下简单的代码: var casper = require("casper").create({ }), utils = require('utils'), http = require('http'), fs = require('fs'); casper.start(); casper.thenOpen('http://www.yahoo.com/', function() { casper.capture('test.png'); }); casper.on('http.status.404', function(resource) { this.echo('wait, this url is 404: ' + resource.url); }); casper.run(function() { casper.exit(); }); 有没有办法赶上http.status代码,不pipe它是什么? 现在我可以在文档中看到如何捕捉特定的代码事件。 如果我只想看看它是什么呢?

我如何使用node.jsdynamic内容页面?

我试图刮一个网站,但我没有得到一些元素,因为这些元素是dynamic创build的。 我在node.js中使用cheerio,我的代码如下所示。 var request = require('request'); var cheerio = require('cheerio'); var url = "http://www.bdtong.co.kr/index.php?c_category=C02"; request(url, function (err, res, html) { var $ = cheerio.load(html); $('.listMain > li').each(function () { console.log($(this).find('a').attr('href')); }); }); 这段代码返回空的响应,因为当页面被加载时, <ul id="store_list" class="listMain">是空的。 内容尚未附上。 如何使用node.js获取这些元素? 我如何刮dynamic内容的网页?

使用Horseman和PhantomJS下载wav文件,丢失数据质量

我使用PhantomJS和HorsemanJS从远程服务器下载wav文件。 但是,当文件是base64编码,并写入一个新的文件,它会丢失质量,使其无法使用。 audio在那里,但它的扭曲导致我认为它是一个编码问题。 我正在使用节点v5在Ubuntu 14.04上运行 下面是我的脚本任何想法也许改善base64编码? var Horseman = require('node-horseman'); var horseman = new Horseman({cookiesFile:'./cookiejar'}); var fs = require('fs'); horseman.on("urlChanged", function(url){ console.log(url); }); horseman.on('consoleMessage', function( msg ){ console.log(msg); }); horseman .userAgent("Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2228.0 Safari/537.36") .open('https://remoteserver.com/audo.aspx?guid=01439900-5361-4828-ad0e-945b56e9fe51') .waitForNextPage() .type('input[name="password"]', process.env.PASS) .type('input[name="username"]', process.env.UN) .click("button:contains('Login')") .waitForNextPage() .evaluate(function(){ var base64EncodeChars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; function base64encode(str) […]