2016-06-26 3 views
0

私は1つのURLを読み込み、選択メニューからすべての項目を選択して複数の銀行口座明細をダウンロードしようとしています。reduceと約束を使用してナイトメアjsでルーピング

reduceを使用してループするには、hereのガイドに従っています。

部分コード:

const statementOptions = [ 
    '1:accepted:1', 
    '3:accepted:3', 
    '4:accepted:4', 
    ... 
] 

nightmare.goto('https://www.homesavings.com') 
//login 
.viewport(900, 800) 
.wait('form[name="Login"]') 
.insert('#userid', config.userid) 
.insert('#password', config.password) 
.click('#submit input') 

// go to Online Statements page 
.wait('a[data-app-code="Online Statements"]') 
.goto('https://www.hslonline2.com/onlineserv/HB/OnlineStatements.cgi') 
.evaluate(statementOptions => statementOptions, statementOptions) 
.then(statementOptions => { 
    return statementOptions.reduce(function(acc, option, index) { 
    console.log(`reduce it: option=${option} index=${index}`) 
    return acc.then(function(results) { 
     return nightmare 
     // wait for the account select box to load.. 
     .wait('select[name="acctRef"]') 
     .select('select[name="acctRef"]', option) 
     //.wait(1000) 
     .click('input[type="submit"]') 
     //.wait(2000) 
     .wait('td a img') 
     .click('td a') 
     .download(`${downloadDir}/bankPDF_${index}`) 
     .then(info => { 
      console.log(`after download. info -> ${JSON.stringify(info, null, 2)}`) 
      results.push(info) 
      return results 
     }) 
     }) 
    }, Promise.resolve([])).then(infos => infos) 
}) 

これを実行した後、そこにtmpフォルダ内の1つのファイルがあり、それが最初の選択オプションに対応しています。

また、ファイル名はbankPDF_0です。私は「何

nightmare:actions .evaluate() fn on the page +3ms 

reduce it: option=1:accepted:1 index=0 
reduce it: option=3:accepted:3 index=1 
reduce it: option=4:accepted:4 index=2 

nightmare:actions .wait() for select[name="acctRef"] element +3ms 
nightmare:actions .select() select[name="acctRef"] +4ms 
nightmare:actions .click() on input[type="submit"] +2ms 
nightmare:actions .wait() for td a img element +4ms 
nightmare:actions .click() on td a +7s 

after download. info => { 
"filename": "ImageRequestor.pdf", 
"mimetype": "application/pdf", 
"receivedBytes": 172446, 
"totalBytes": 172446, 
"path": "/Users/cdock/Desktop/bank-statements/tmp/bankPDF_0", 
"state": "completed" 
} 

nightmare:actions .wait() for select[name="acctRef"] element +2s 
nightmare:actions .select() select[name="acctRef"] +1ms 
nightmare:actions .click() on input[type="submit"] +1ms 
nightmare:actions .wait() for td a img element +7s 
nightmare:actions .click() on td a +2ms 

after download. info => { 
"filename": "ImageRequestor.pdf", 
"mimetype": "application/pdf", 
"receivedBytes": 172446, 
"totalBytes": 172446, 
"path": "/Users/cdock/Desktop/bank-statements/tmp/bankPDF_0", 
"state": "completed" 
} 

nightmare:actions .wait() for select[name="acctRef"] element +1s 
nightmare:actions .select() select[name="acctRef"] +1ms 
nightmare:actions .click() on input[type="submit"] +1ms 
nightmare:actions .wait() for td a img element +6s 
nightmare:actions .click() on td a +2ms 

after download. info => { 
"filename": "ImageRequestor.pdf", 
"mimetype": "application/pdf", 
"receivedBytes": 172446, 
"totalBytes": 172446, 
"path": "/Users/cdock/Desktop/bank-statements/tmp/bankPDF_0", 
"state": "completed" 
} 

:ここ

は、コンソール出力の一部である彼らは、コールバックを減らすの内側にあるものののでオプションとインデックスは、ネストされた悪夢のセクションの内側に反復されていません

... reduce /約束を使ってループするのは間違っていますか?

答えて

0

回答here

常に取り付けられた第1のハンドラによって処理されるダウンロードしたファイルを強制的に、複数のイベントハンドラに.download()複数回、結果を用いて、nightmare-inline-downloadライブラリにバグがありhere

関連する問題