问题描述
限时送ChatGPT账号..是否可以在 node.js 应用程序中运行 wget
?我想要一个脚本来抓取一个站点,并下载一个特定的文件,但是文件链接的 href
经常更改.因此,我认为最简单的方法是找到链接的 href
,然后对其执行 wget.
Is it possible to essentially run a wget
from within a node.js app? I'd like to have a script that crawls a site, and downloads a specific file, but the href
of the link that goes the file changes fairly often. So, I figured the easiest way to go about doing it would be to find the href
of the link, then just perform a wget on it.
谢谢!
推荐答案
您可以使用 child_processes 运行外部命令:
You can run an external command using child_processes:
http://nodejs/docs/latest/api/child_process.html#child_process_child_process_exec_command_options_callback
var util = require('util'),
exec = require('child_process').exec,
child,
url = 'url to file';
child = exec('wget ' + url,
function (error, stdout, stderr) {
console.log('stdout: ' + stdout);
console.log('stderr: ' + stderr);
if (error !== null) {
console.log('exec error: ' + error);
}
});
这篇关于如何使用 node.js 复制 wget 的功能?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
更多推荐
[db:关键词]
发布评论