Tag: phantomjs

为什么此代码会导致使用幻影模块的Node.js挂起

如果我改变这个: 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(); }); }); }); }); 对此: 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? ", […]

我可以/我怎么能将一个Selenium webdrivertesting脚本从node.js转换为phantomjs – ghostdriver?

我最近开始和Selenium一起工作,为了让生活更轻松,我开始使用节点来运行我的脚本,以便可以直观地监视testing。 我现在面临的挑战是将其转换为可以作为无头testing运行。 不幸的是,我所遇到的大部分资源只能用Java或Python使用phantomjs和ghostdriver。 我的老板要我通过没有Java或Python的phantomjs来运行testing。 最终,这些testing将通过不带GUI的服务器上的Linux VM远程运行。 目前,我正在使用Mac OS X 10.8进行testing,并且仍然有很多桥接以便达到我的目标。 我最重要的问题是,是否可以通过端口从phantomjs运行脚本而不使用Java或Python? 我花了好几个小时的时间仔细研究了我所能得到的资源,而且我没有find解决办法。 如果是这样,我该如何正确地初始化testing运行无头? 这是我如何编写我的functiontesting的开始。 我想正确地将function从firefox切换到phantomjs,并且能够使用合适的端口来运行它。 其余的testing导航到一个特定的网站,通过一个小部件login,然后进一步导航到该地区,我将build立进一步的testing,在我得到这个工作后操纵。 var webdriver = require('selenium-webdriver'), SeleniumServer = require('selenium-webdriver/remote').SeleniumServer; var server = new SeleniumServer("Path/selenium-server-standalone-2.39.0.jar", { port: 8910 }); server.start(); var driver = new webdriver.Builder(). usingServer(server.address()). withCapabilities(webdriver.Capabilities.firefox()). build(); testing工作完美,但我是新来的,所以我可以忽略一些愚蠢的东西。 请让我知道做了什么调整,以便通过幻影无法运行。 当我尝试使用节点运行脚本后切换functionphantomjs它产生的 "/Selenium/node_modules/selenium-webdriver/phantomjs.js:22 LogLevel = webdriver.logging.LevelName, ^ TypeError: Cannot read property 'LevelName' of […]

phantomjs版本似乎并没有更新

现在我一直在试图把这个问题解决一下。 希望你们中的一些人能够帮助解决这个问题。 这一切都开始与我想尝试https://github.com/metaskills/mocha-phantomjs 。 所以我按照说明跑了 npm install -g mocha-phantomjs phantomjs 思考一切都很好,我写了我的testing代码,跑了 mocha-phantomjs test.js 这是我的第一个问题 : mocha-phantomjs requires PhantomJS > 1.9.1 起初似乎很简单,我可能只需要在幻影上升级版本。 看了最新版本,发现它是1.9.7-1,所以我执行了: sudo npm install phantomjs@1.9.7-1 -g 这是我的第二个问题 : $ phantomjs -v 给我 1.8.1 即使我刚刚安装版本1.9.7-1 我做了一个快速的命令来validation我确实安装了1.9.7-1,我在我的项目文件夹中做了这个: $ npm ls phantomjs Project@0.0.1 /home/ubuntu/project └── phantomjs@1.9.7-1 extraneous 困惑,我在/ usr / lib / node_modules / phantomjs中的package.json上做了一个vim,得到了这个: "name": "phantomjs", […]

mocha-casperjs多客户端node.js应用程序的无头testing

我有一个运行在Sails.js MVC框架上的node.js应用程序。 该应用程序支持来自多个客户端使用socket.io实时连接。 它支持不同的angular色。 例如,您可以以标准用户身份或主持人身份login。 为了testing,我使用mocha-casperjs(以及chai和其他对我的问题不重要的东西),并使用grunt mocha_phantomjs从grunt运行testing。 testing在我的项目的根文件夹中的Gruntfile.js文件中指定。 他们是这样指定的: Gruntfile.js: mocha_casperjs: { files: { src: [ 'test/single-client.js', 'test/multi-client.js', ] } } 这是我想validation的一个testing案例:一旦主持人点击一个特定的button,一个div.container应该出现在主持人的视图以及标准用户的视图。 现在,testing单客户端方面效果很好。 这是一个基本的情况: testing/单client.js: describe('Clicking on a Button as a Moderator', function() { it('results in div.container to appear on the Moderators view', function() { casper .start('http://localhost:1337') .logInAsMod() //Note: This is pseudocode for submitting a […]

banquo / phantom nodejs错误 – 无法读取未定义的属性'createPage'

即时通讯试图运行https://github.com/ajam/banquo-server和接收和错误 无法读取未定义的属性“createPage” Express server listening on port 3000 Requesting http://america.aljazeera.com /root/banquo-server/node_modules/banquo/src/banquo.js:36 ph.createPage(openPage); ^ TypeError: Cannot read property 'createPage' of undefined at createPage (/root/banquo-server/node_modules/banquo/src/banquo.js:36:7) at /root/banquo-server/node_modules/node-phantom/node-phantom.js:65:6 at null._onTimeout (/root/banquo-server/node_modules/node-phantom/node-phantom.js:43:5) at Timer.listOnTimeout (timers.js:110:15) error: Forever detected script exited with code: 1 error: Script restart attempt #7 connect.multipart() will be removed in connect 3.0 visit https://github.com/senchalabs/connect/wiki/Connect-3.0 for alternatives […]

从js中用node.js和horseman刮取html

我正试图从这个页面的工资信息刮面糊数组: https : //www.swishanalytics.com/optimus/mlb/dfs-batter-projections 我正在使用node.js和node-horseman。 这是我的代码: var Horseman = require('node-horseman'); var horseman = new Horseman(); horseman.open('https://www.swishanalytics.com/optimus/mlb/dfs-batter-projections'); if (horseman.status() === 200) { console.log('[+] Successful page opening') horseman.screenshot('image.png'); console.log(horseman.html()); } horseman.close(); 问题是从horseman.html返回()仍然是很多的JavaScript,不能提取像cheerio的东西。 我怎样才能以编程方式执行JavaScript? 例如,如果我在相同的链接上查看源代码,则可以看到包含打击者的区域开始 function Model(){ this.batterArray = [{"team_short":"rockies","mlbam_id":"571448","player_name":"Nolan Arenado", 显然,这仍然是JavaScript …我假设在某些时候,它必须执行并转换为HTML浏览器呈现?

nodejs – 检查图像是否为空

我正在创build一个testing应用程序,吐出用户input的URL图像。 截图采取phantomjs + nightmarejs。 有时用户input不存在的URL,所以图片截图是空白的。 在nodejs中有没有lib允许我检查图像是否为空? 或者更好的方法? 谢谢!

PhantomJS的Phantom节点包等效代码

我很难转换这个代码,使它可以在节点服务器中使用。 所以这段代码被编写成在PhantomJS进程(即$:phantomjs index.js)中运行,但是我想使用程序包require(“phantom”)在节点服务器中运行它。 我有困难让这两个callback工作,但是。 page.onLoadFinished = function(status){ console.log("Load Finished"); }; page.onUrlChanged = function(){ console.log("URL Changed"); }; 这是我试图控制整个情况的可悲尝试。 phantom.create(['–ignore-ssl-errors=yes','–load-images=no']).then(function(ph) { console.log("here"); ph.createPage().then(function(page) { page.property('onResourceRequested', function(requestData, networkRequest) { console.log(requestData.url); }); page.open('https://example.com/login').then(function(status) { console.log(status); if (status !== 'success') { console.log("failed connection")} else { page.evaluate(function() { document.getElementById('email').value = "stuff"; document.getElementById('password').value = "things"; setTimeout(document.getElementsByTagName('button')[0].click(),5000); console.log("login attempt"); setTimeout(document.URL, 2000); }); page.onLoadFinished […]

使用nodejs和phantomjs进行dynamic抓取

首先,我成功安装了PhantomJs和它的npm接口幻象 。 我已经设置了代码来加载我的页面,使用新的语法(这里发布的所有其他问题都是基于旧的代码语法,或者我错过了一些东西)。 这是我试图刮的来源 。 现在,右侧边栏,一个假select靠近“公爵”,另一个是dynamic生成的,我不明白为什么phantomjs不拾起它们。 遵循我的代码: var sito = "http://bicincitta.tobike.it/"; var sitepage = null; var phInstance = null; var phantom = require('phantom') phantom.create() .then((instance) => { phInstance = instance; return instance.createPage(); }) .then((page) => { sitepage = page; return page.open(sito); }) .then((status) => { console.log(status); return sitepage.property('content'); }) .then((content) => { console.log(content); sitepage.close(); phInstance.exit(); […]

无法使用phantomJS获取iframe的元素

我正在寻找一种方法来控制文档中的元素。 问题是,该文件被附加到一个iFrame。 这是一个例子: .goto('https://wirecard-sandbox-engine.thesolution.com/engine/hpp/') .use(iframe.withFrameName('wc', function (nightmare) { nightmare .type('#account_number', accountNumber) .screenshot(resultfolder + '\\06-Card-Number.png') .type('#card_security_code', testData.securityCode) .selectIndex('#expiration_month_list', 1) .selectIndex('#expiration_year_list', 4) .click('span[id="hpp-form-submit"]') })) 我在上面要做的是: 获取与url的iFrame。 使用这个来获得对iFrame中每个元素的控制。