簡體   English   中英

nodejs exec Wget命令

[英]nodejs exec Wget command

我正在編寫一個nodejs應用程序,以使用“ wget” unix命令下載整個網站,但是下載的頁面內部存在一些URL問題,.html出現在文件末尾,例如

<img src=“images/photo.jpeg.html”> or <script src=“js/scripts.js.html”>

我正在使用的代碼如下:

    var util = require('util'),
    exec = require('child_process').exec,
    child,
    url = 'http://www.example.com/';
child = exec('wget --mirror -p --convert-links --html-extension -e robots=off -P /destination_folder/ ' + url,
  function (error, stdout, stderr) {
    console.log('stdout: ' + stdout);
    console.log('stderr: ' + stderr);
    if (error !== null) {
      console.log('exec error: ' + error);
    }
});

注意:如果我直接在Unix shell上使用此命令(wget --mirror -p --html-extension --convert-links -e robots = off -P。http: //www.example.com ),它將正常工作。

編輯 :這是運行nodejs腳本后返回的日志:

--2017-04-04 11:49:49--  http://www.example.com/css/style.min.css
Reusing existing connection to www.example.com:80.
HTTP request sent, awaiting response... 304 Not Modified
File ‘/destination_folder/www.example.com/css/style.min.css.html’ not modified on server. Omitting download.

FINISHED --2017-04-04 11:50:11--
Total wall clock time: 22s
Downloaded: 50 files, 1.2M in 1.4s (855 KB/s)
/destination_folder/www.example.com/css/style.min.css.html: No such file or directory
Converting links in /destination_folder/www.example.com/css/style.min.css.html... nothing to do.
exec error: Error: stderr maxBuffer exceeded

我不明白問題出在哪里,請您能幫我嗎?

謝謝

execstdoutsterr之間使用一個有限的緩沖區。

如果要下載的文件很大,則緩沖區可能空間不足。 嘗試使用exec spawn intestad。 供您參考: spawn與Node.js的exec之間的區別

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM