gpt4 book ai didi

javascript - 将 URL 发送到 Phantomjs?

转载 作者:行者123 更新时间:2023-11-29 09:53:47 25 4
gpt4 key购买 nike

截图.js

var page = require("webpage").create();
var homePage = "http://www.google.com/";
page.open(homePage);
page.onLoadFinished = function(status) {
var url = page.url;
console.log("Status: " + status);
console.log("Loaded: " + url);
page.render("google.png");
phantom.exit();
};

航站楼:

bin/phantomjs screenshot.js

问题:有什么办法可以在 screenshot.js 之外以某种方式向 phantomjs 发送 URL(上面 var homePage 的值),这样它就不会在脚本中硬编码了吗?

最佳答案

将url添加到命令行

bin/phantomjs screenshot.js http://www.google.com/

这里有一个来自文档的例子:https://github.com/ariya/phantomjs/blob/master/examples/arguments.js

var system = require('system');
if (system.args.length === 1) {
console.log('Try to pass some args when invoking this script!');
} else {
system.args.forEach(function (arg, i) {
console.log(i + ': ' + arg);
});
}
phantom.exit();

关于javascript - 将 URL 发送到 Phantomjs?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16844436/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com