Tag: phantomjs

phantomjs / slimerjs输出到标准输出为空

我一直在试图用phantomjs或slimerjs从网站捕捉一个pngs序列,然后将输出发送到/ dev / stdout并将其传送到ffmpeg来制作video。 像这样: phantomjs test.js | ./ffmpeg -analyzeduration 2147483647 -probesize 2147483647 -y -c:v png -f image2pipe -r 10 -i – -c:v libx264 -pix_fmt yuv420p -movflags +faststart test.mp4 test.js: var page = require('webpage').create(); page.clipRect = { top: 0, left: 0, width: 900, height: 800}; page.viewportSize = { width: 900, height: 800}; var url = […]

使用PhantomJs将PDF转换为图像

我使用PhantomJs将网页转换为图像,而且工作正常,这里是我的代码来做到这一点 phantomjs.exe rasterize.js http://myurl.com/mypage/ out_put_image.png 这工作得很好,但是当我加载一个URL定位任何PDF,这是无法截图的PDF,并给错误为“无法加载地址! 我的代码是这样的 phantomjs.exe rasterize.js http://myurl/myfolder/mypdf.pdf pdf_image.png 幻影无法做到这一点:( 有没有办法做到这一点? 或与任何其他的JS / PHP框架来做到这一点? 任何帮助将是伟大的。

节点幻像显示生成的PDF页面的数量

我正在面临的问题,以获得生成的PDF页面的数量phantomjs。 基本上我用nodejs使用phantomjs,我想在第5页显示总页数。 function generatePdf() { // Load ejs template fs.readFile(__dirname + '/../pdf' + pdfpath, 'utf8', function (err, data) { var fileName = __dirname + '/pdfdata/' + f.formType + f.formId + '.pdf'; // Render the page to variable. var html = ejs.render(data, pdfJSON); fs.writeFile(__dirname + '/pdfdata/test.html', html, function (err) { if (err) throw err; }); // […]

在Windows 7 64位上为node.js安装PhantomJS网桥时如何解决错误?

当我尝试在我的Windows 8 64位安装phantom时出现以下错误。 $ npm install phantom E:\ pay \ node_modules \ phantom \ node_modules \ dnode \ node_modules \ weak> node“C:\ Program Files \ nodejs \ node_modules \ npm \ bin \ node-gyp-bin \\ .. \ .. \ node_modules \ node- gyp \ bin \ node-gyp.js“重build gyp ERR! configuration错误 gyp ERR! 堆栈错误:产卵ENOENT gyp ERR! […]

如何将摩卡testing与摩卡幻影testing相结合

testing用例: 服务器/ appTest.js 客户/ clientTest.js clientBundle.js clientTest.html 都是摩卡testing。 对于客户端testing,我使用sinon,并使用它们来生成一个包 – clientBundle.js并使用mocha-phantomjs进行无头testing。 现在我已经将npm test定义为mocha test/server && mocha-phantomjs test/clientTest.html 。 它给我两个分别的结果。 我怎么能把它们合并成一个 – 比如说mocha test/all.js 在test/all.js里面试过require()s 。 mocha-phantomjs不能用作节点内的库。 它只能用作CLI。

幻影挂在主页上

我有这个代码作为test.js: var page = require('webpage').create(); console.log('The default user agent is ' + page.settings.userAgent); page.settings.userAgent = 'Mozilla/5.0'; //page.onResourceRequested = function(request) {}; //page.onResourceReceived = function(response) {}; page.open('http://www.skadden.com',function(status){ console.log("Status: " + status); phantom.exit(); }); 当我运行这些命令时,为什么Phantom会间歇性挂起? phantomjs –debug=true –web-security=false –load-images=true test.js 挂起在[DEBUG]networking – 资源请求错误:203(“错误下载http://www.skadden.com/sites/all/themes/skadden_​​main/images/menu_links.png – 服务器答复:未find”)URL:“ http://www.skadden.com/sites/all/themes/skadden_​​main/images/menu_links.png “ phantomjs –debug=true –web-security=false –load-images=false test.js 作品有时,但也将挂在[debugging] CookieJar – 保存“has_js = 1;域= […]

Phantomjs 2.0 SocketIO每个连接需要1000毫秒

我使用PhantomJS 2.0并试图在PhantomJS和NodeJS之间testingsocket.io。 它的工作原理,但每个连接需要大量的时间(约1000毫秒)。 我曾在Chrome上试过,它只需要1-2ms。 看来PhantomJS的page.evaluate中的socket.io不是socket.io! 这是我使用CasperJS的testing代码: var casper = require('casper').create({ clientScripts:["socket.io.js"] }); casper.start('http://localhost:8080'); casper.page.onConsoleMessage = function(msg) { console.log(msg); }; }; casper.then(function(){ this.evaluate(function(){ var socket = io.connect('http://localhost:8080'); socket.on('news', function (data) { socket.emit('senddata', { time: new Date().getTime() }); }); }) }) casper.wait(5000); casper.run(); 在NodeJS服务器上,我使用下面的代码: var app = require('http').createServer(handler) var io = require('socket.io')(app); var fs = require('fs'); app.listen(8080); […]

在phantom-html2pdf之前运行一个js脚本,从html生成pdf

你好,我希望有一些关于phantom-html2pdf模块的帮助。 我想从一个HTML生成一个PDF文件,为此我使用phantomjs和phantom-html2pdf。 我的代码是: var pdf = require('phantom-html2pdf'); exports.makePdf = function (req, res, next) { console.log("pdf function"); console.log(req.body); var html = req.body.html, css = req.body.css, js = req.body.js; var options = { "html" : html, "css" : css, "js" : js, // "runnings" : "Path to runnings file. Check further below for explanation.", "deleteOnAction" : true […]

使用node.js幻像模块将cookie作为string添加到幻像页面

我幻影服务器运行,收到一个附加在头里面的cookie的请求。 我必须使用这个cookie,而从幻影打开一个页面。 更确切地说,我有一个string,我需要添加作为一个cookie,而打开一个页面。 我已经使用节点模块模型(npm install phantom)安装了幻影。 以下是我正在尝试的代码,但无法看到任何Cookie: phantom.create(function(ph){ ph.createPage(function (page) { console.log(page); var cookieAdded = ph.addCookie({ 'name': 'OSF Cookie', 'value': req.headers.cookie, 'domain': req.headers.host }); console.log(cookieAdded); page.open(url, function (status) { if (status == 'success') { console.log("Success"); page.getCookies(function(cookie){ console.log(cookie); }); page.evaluate( function () { console.log(document.headers); return document.documentElement.outerHTML; }, function (content) { // console.log(content); res.send(content); console.log('RESPONSE SEND') ph.exit(); […]

ChaiJs不出现在Phantomjs-node injectJS的窗口中

我正在尝试将一些脚本注入到使用phantomjs-node桥加载到PhantomJs中的页面中。 当我将MochaJs注入页面时,我可以评估和window.mocha对象可用。 但是当我注入chaiJs时, window.chai对象不可用。 我已经validation了injectJs调用将true状态传递给了callback,表明脚本被成功注入了,并且我也证实了window.chai和window.mocha在注入之后立即可用: http: //plnkr.co/edit/gMzjavJqpNDNeYipmBHG?p=preview 我甚至尝试使用page.includeJs('http://cdnjs.cloudflare.com/ajax/libs/chai/1.10.0/chai.min.js')来确保在cloudflare cdn版本中没有差异我有的npm安装版本,仍然不能正常工作。 我究竟做错了什么? page.injectJs(nodeLibDir + '/chai/chai.js', function(){ //page.injectJs(nodeLibDir + '/mocha/mocha.js', function(){ page.evaluate(function(){ //window.callPhantom(window.mocha.constructor.name); window.callPhantom(window.chai.version); }, function(){ console.log('finished'); page.close(); res.json({status: status}); res.end(); }); });