Node.js:如何在url中添加变量作为输入

Node.js : how add variable as input in url

本文关键字:变量 添加 输入 url js Node      更新时间:2023-09-26

我想使用这个幻影代码,但在node.js 中找不到system.args[1]的等效代码

    var phantom = require('phantom');
   // var page = new WebPage();
   // var system = require('system');
   // var sBlob = system.args[1];
    var sUrl = 'file:///C:/Users/editor.html?Blob='+sBlob;
    phantom.create(function(ph) {
        ph.createPage(function(page) {
            page.open(sUrl, function(status) {
                console.log("opened diagram? ", status);
                page.evaluate(function() {
                    return document.getElementById("GraphImage").src;
                }, function(result) {
                    console.log(result)
                    ph.exit();
                });
            });
        });
    }, {
        dnodeOpts : {
            weak : false
        }
    });

如果您将脚本作为$ node script.js theargument 运行

你应该能够使用获得它

// the first argument is node and 
//the second is the script name, none of them should be relevant
var args = process.argv.slice(2);
var sBlob = args[0];