Tag: phantomjs

Phantom.js填写字段,点击提交,现在卡在访问下一页

我已经开始phantom.js(顺便说一句,我恋爱了)。 我试图让无头浏览器去我的PHPpipe理面板,用用户名和密码login,并从login后redirect到的页面,我想从一个div标签中获取一些文本。 到目前为止,我设法成功填充字段,创build一个单击事件,甚至find对div标签的DOM部分的访问,并获得inner.Text。 对我来说唯一缺less的部分是当phantom.js单击一个button(在这种情况下是loginbutton)时要做什么,它将login我并更改页面内容。 .click();后我找不到如何处理。 事件。 这是我迄今为止的代码(顺便说一下,它是一个很好的开始…) var page = new WebPage(); page.open("the url comes here", function(status){ if(status != "success"){console.log('fail loading the page');} page.evaluate(function(){ var arr = document.getElementsByName("formname"); arr[0].elements["username"].value="username here"; arr[0].elements["password"].value="password here"; arr[0].elements["submit"].click(); return; } phantom.exit() }); 我想要的代码运行在它后面的页面上 console.log(window.frames[1].document.getElementById('status').innerHTML) 所以剩下的唯一问题就是如何处理redirect并在其他页面上启动脚本。 谢谢,

使用Spooky.js运行示例代码时出错

我是新来的整个phantom.js , casper.js , casper.js和spooky.js 。 我已经安装了所有的东西(在Windows中),更新PATH并遵循这个例子: https://github.com/WaterfallEngineering/SpookyJS 我得到这个错误: C:\node_modules\spooky>node examples/hello.js events.js:68 throw arguments[1]; // Unhandled 'error' event ^ Error: Child terminated with non-zero exit code 127 at Spooky._spawnChild.Spooky._instances.(anonymous function) (C:\node_module s\spooky\lib\spooky.js:82:17) at ChildProcess.EventEmitter.emit (events.js:96:17) at Process._handle.onexit (child_process.js:678:10) 任何人有任何线索为什么和如何解决它? 我运行casperjs googlelinks.js就好了。 但是使用node.js和spooky.js ,这给我带来了麻烦。

phantomjs npm安装在代理后面失败

试图在企业代理后面通过npm包装来安装PhantomJS 。 我已经设置了http_proxy和https_proxy环境variables,以便npm本身能够与registry进行通信: export http_proxy=my-company-proxy.com:80 export https_proxy=my-company-proxy.com:80 但是当谈到phantomjs的node.js阶段时,我得到一个Protocol不支持的错误: http.js:1711 throw new Error('Protocol:' + options.protocol + ' not supported.'); ^ Error: Protocol:my-company-proxy.com: not supported.

PhantomJS Web服务器与节点?

这里有什么区别? 我想创build一个排队工作的小API,但我不知道应该使用哪个。 我倾向于使用Node,但是我明白了为PhantomJS设置一个Web服务器模块的意义。

如何将数据从casperJS传递到nodeJS?

我在casperJS中构build了一个刮板,用于从Google+页面中提取数据。 它工作出色。 现在我想能够在我的nodeJS服务器中添加一个API GET调用,它将抓取这些数据并以JSON格式返回。 除了在这里的testing场景,我没有find任何关于如何完成这个任务的文档或内容。 还有一些鬼怪 ,但在9个月内还没有更新,人们都说它很破碎。 任何指导,使之成为可能将不胜​​感激。

如何调用SpookyJS中的函数?

我有一个叫做clickMore的函数: function clickMore(max, i){ i = i || 0; if ((max == null || i < max) && this.visible(moreButton)) { // synchronous // asynchronous steps… this.thenClick(moreButton); // sometimes the click is not properly dispatched this.echo('click'); this.waitUntilVisible(loadingButton); this.waitUntilVisible(moreButton, null, function onTimeout(){ // only placeholder so that the script doesn't "die" here if the end is reached […]

减less无限循环中的phantomjs / casperjs / spookyjs内存使用

我试图刮一个页面,使用phantomjs casperjs和幽灵般的无限滚动。 它应该继续点击更多的button,并从结果中的新链接,直到手动停止。 然而脚本开始使用越来越多的内存,直到它崩溃。 我写了下面的脚本,有没有一种方法来优化它,所以它不会使用更多的内存: function pressMore(previousLinksLength) { this.click('#projects > div.container-flex.px2 > div > a'); this.wait(1000, function() { links = this.evaluate(function() { var projectPreview = document.querySelectorAll('.project-thumbnail a'); return Array.prototype.map.call(projectPreview, function(e) { return e.getAttribute('href'); }); }); this.emit('sendScrapedLinks', links.slice(previousLinksLength)); // repeat scrape function pressMore.call(this, links.length); }); } // spookyjs starts here spooky.start(scrapingUrl); //press the more button spooky.then(pressMore); […]

渲染pdf时,PhantomJs将页眉边距设置为0

我正在使用Node.js和模块phridge(版本1.0.3)来渲染与PhantomJs的pdf。 我想在页眉和页脚中没有任何页边空白的情况下渲染pdf。 目前,我只发现一个黑客通过负左右边距去除左右边距。 用pagenumbers打印页眉和页脚的例子可以在这里find: https : //github.com/ariya/phantomjs/blob/master/examples/printheaderfooter.js // creates a new webpage internally var page = phantom.createPage(), outputFile = path.join(options.destDir, options.destFile); /*global window:false */ // page.run(fn) runs fn inside PhantomJS page.run(html, outputFile, options.header, options.footer, options.delay, function (html, outputFile, header, footer, delay, resolve /*, reject*/) { // Here we're inside PhantomJS, so we can't reference variables […]

对同一个幻象实例使用createPage()两次

我试图用PhantomJS设置摩卡testing,而且我遇到了一个问题,我无法使用相同的幻像实例来创build多个页面。 第一个testing用例运行得很好,但第二个testing用例运行良好。 我只想使用一个实例,因为它应该更快。 var assert = require('assert'); var phantom = require('phantom'); var path = require('path'); var ph; describe('document', function() { before(function(done) { // Create only one phantom instance for the whole suite this.timeout(10000); // Prevent test case from aborting while phantom loads phantom.create(function(p) { ph = p; done(); }, { dnodeOpts: {weak: false} }); }); […]

如何用Node.js保存图像(以base64编码的stringforms传入)

我在我的Meteor应用程序上创build了一个带有Phantom.js的HTML5canvas,我试图将canvas图像保存在磁盘上。 问题:保存的图像文件似乎已损坏(无法在图像查看器中打开)。 我从HTML5的Canvas.toDataUrl方法得到了一个base64编码的PNG图像。 这是我从Canvas.toDataUrl()函数保存的输出如下所示:WzMyLDMyLDU4LDQ3LDEwOSwxMTEsMTAwLDExNywxMDgsMTAxLDExNSw0NywxMTksMTAxLDk4LDExMiw5NywxMDMsMTAxLDQ2LDEwNiwxMTUsNTgsNTAsNTYsNDksMTBd 这是我的保存程序: var buffer = new Buffer(JSON.stringify(CanvasString)).toString('base64'); var fs = Meteor.npmRequire("fs"); var fullFileName = fileName + '.png'; fs.writeFileSync(fullFileName, buffer, "binary"); 我可以使用文本编辑器(如上面的输出)将保存的图像作为明文进行查看。