简体   繁体   English

流星PhantomJS动态URL参数

[英]Meteor PhantomJS Dynamic URL parameters

I've installed PhantomJS in my Meteor app using the instructions in the answer here: Installing/Using Phantom.js with Meteor but the method involved: 我已经按照以下答案中的说明在我的Meteor应用程序中安装了PhantomJS: 通过Meteor安装/使用Phantom.js,但涉及的方法:

(private/phantomDriver.js) (私人/phantomDriver.js)

var page = require('webpage').create();
page.open('http://github.com/', function (){
  console.log('Page Loaded');
  page.render('github.png');
  phantom.exit();
});

has a set URL... how can I pass parameters to the file to change the URL? 有一个设置的URL ...如何将参数传递给文件以更改URL? eg 例如

page.open(URL, etc...)

This: 这个:

var URL = newURL
spawn(phantomjs.path, ['assets/app/phantomDriver.js', URL]);

Logs 日志

"stdout: ReferenceError: Can't find variable: URL" to the console. 控制台的“ stdout:ReferenceError:找不到变量:URL”。

Artjom B.'s link didn't solve the problem (needed to use spawn(phantomjs.path) whereas exec expects a string I don't know of) - though it did lead me to the answer so, thanks! Artjom B.的链接不能解决问题(需要使用spawn(phantomjs.path)exec需要一个我不知道的字符串)-尽管它确实使我找到了答案,谢谢!

Also made use of require('system').args; 还利用了require('system').args; to access the arguments sent via spawn 访问通过spawn发送的参数

Final code: 最终代码:

server.js: server.js:

spawn(phantomjs.path, ['assets/app/phantom_driver.js',URL]);

private/phantomDriver.js 私人/phantomDriver.js

var page = require('webpage').create();
var args = require('system').args;
var URL = args[1]

page.open(URL, function(status) {
  console.log('Page loaded. Status: ' + status);
  page.render('github.png');
  phantom.exit();
})

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM