如何在噩梦中下载多个文件

时间:2017-11-02 23:30:06

标签: javascript node.js headless-browser nightmare

所以我已经设置了这个

const Nightmare = require('nightmare');
require('nightmare-inline-download')(Nightmare);
require('nightmare-download-manager')(Nightmare);

const nightmare = Nightmare({ show: false, waitTimeout: 2500, gotoTimeout: 5000 });

var download = ( async () => {
    const url = "someurl"

    nightmare.on('download', function(state, downloadItem){
        if(state == 'started'){
            nightmare.emit('download', downloadItem.filename, downloadItem);
        }
    });

    let test = nightmare
        .downloadManager()
        .goto(url, {Authorization: "Basic"})
        .wait("#summary-val")
        .evaluate( () => {
            document.querySelectorAll("#attachments li .attachment-thumb a").forEach( function(elem) {
                elem.click()
            })
        })
        .waitDownloadsComplete()
        .end()
        .then(data => {
        })
        .catch((error) => {
            console.error('Search failed:', error);
        });
})

download();

然而,这仅下载最后一个文件。执行click("#attachments li .attachment-thumb a")只会导致第一个文件被下载。

那么如何以递归方式下载所有文件?

0 个答案:

没有答案