sha*_*nar 1 url-parameters phantomjs
我在Windows机器上,使用标准命令行工具并使用PhantomJS和修改后的rasterize.js代码。我遇到的问题是当我传递url时http://time.com/3274245/e-cigarettes-debate/?utm_source=feedburner&utm_medium=feed&utm_campaign=Feed:+time/topstories+(TIME:+Top+Stories)。我已经重定向了StandardOutput和StandardError和,这就是上面的URL所提供的。
标准输出
Usage: rasterize.js URL filename [paperwidth*paperheight|paperformat] [zoom]
paper (pdf output) examples: "5in*7.5in", "10cm*20cm", "A4", "Letter"
Run Code Online (Sandbox Code Playgroud)
标准错误
'utm_source' is not recognized as an internal or external command,
operable program or batch file.
'utm_medium' is not recognized as an internal or external command,
operable program or batch file.
'utm_campaign' is not recognized as an internal or external command,
operable program or batch file.
Run Code Online (Sandbox Code Playgroud)
所以问题是,有什么办法可以解决网址中的参数问题?
请让我知道是否缺少任何信息,或者是否需要澄清。
我将在rasterize.js下面添加我的修改内容。
var page = require('webpage').create(),
system = require('system'),
address, output, size;
page.settings.userAgent = 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:31.0) Gecko/20100101 Firefox/31.0';
if (system.args.length < 3 || system.args.length > 5) {
console.log('Usage: rasterize.js URL filename [paperwidth*paperheight|paperformat] [zoom]');
console.log(' paper (pdf output) examples: "5in*7.5in", "10cm*20cm", "A4", "Letter"');
phantom.exit(1);
} else {
address = system.args[1];
output = system.args[2];
page.viewportSize = { width: 1200, height: 1200 };
if (system.args.length > 3 && system.args[2].substr(-4) === ".pdf") {
size = system.args[3].split('*');
page.paperSize = size.length === 2 ? { width: size[0], height: size[1], margin: '0px' }
: { format: system.args[3], orientation: 'portrait', margin: '1cm' };
}
if (system.args.length > 4) {
page.zoomFactor = system.args[4];
}
page.open(address, function (status) {
if (status !== 'success') {
console.log('Unable to load the address!');
phantom.exit();
} else {
window.setTimeout(function () {
page.render(output);
phantom.exit();
}, 10000);
}
});
}
Run Code Online (Sandbox Code Playgroud)
在Windows cmd中,您需要在可能带有特殊字符的参数周围使用引号。=当发生故障时,A 是一个很好的选择。
phantomjs rasterize.js "http://time.com/..." time.png
Run Code Online (Sandbox Code Playgroud)
特别是对于此页面,您可能需要禁用网络安全性:
phantomjs --web-security=false rasterize.js "http://time.com/..." time.png
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1747 次 |
| 最近记录: |