2016-10-24 6 views
0

ログインページの背後にある重いJSONをダウンロードしようとしています。 文書は約5MBで、接続に約60秒かかることがあります。このコードを試しましたが、結果として空のオブジェクトが残っています。 何が問題なのですか? ありがとう!悪夢のあるログインページの後ろにJSONをダウンロード

var Nightmare = require('nightmare'); 
var nightmare = Nightmare({ 
    typeInterval: 300, 
    show: true 
}); 

nightmare 
    .goto('https://pageThatRequireToLoginThenDiplayJsonAsText.com') 
    .type('[name=email]', '') 
    .wait(1000) 
    .type('[name=email]', 'myemail') 
    .wait(1000) 
    .type('[name=password]', '') 
    .wait(1000) 
    .type('[name=password]', 'mypassword') 
    .click('[type=submit]') 
    .wait(25000) 
    .wait(25000) 
    .evaluate(function (page, done) { 

    document.documentElement 
    done() 
    }) 
    .end() 
    .then(function (result) { 
    // fs.writeFileSync('testOutput.json', JSON.stringify(result)); 
    console.log(JSON.stringify(result)) 
    }) 
    .catch(function (error) { 
    console.error('failed:', error); 
    }); 

ナイトメアバージョン:2.8.1

+0

ドキュメントを返すことはないので、 'result'がnullであるという謎はありません。 –

+0

ご返信ありがとうございます。 私は悪夢を使用します。 結果が返っても同じ結果が得られます。 :/ –

+0

ナイトメアのバージョン2.8.1を使用しています。あなたはそれについてどう思いますか? –

答えて

0

は答えを見つけました。 基本的に、私はちょうど2回目のURLを読み込まなければなりませんでした。

var Nightmare = require('nightmare'); 
var nightmare = Nightmare({ 
    typeInterval: 300, 
    show: true 
}); 

nightmare 
    .goto('https://pageThatRequireToLoginThenDiplayJsonAsText.com') 
    .type('[name=email]', '') 
    .wait(1000) 
    .type('[name=email]', 'myemail') 
    .wait(1000) 
    .type('[name=password]', '') 
    .wait(1000) 
    .type('[name=password]', 'mypassword') 
    .click('[type=submit]') 
    .wait(25000) 
    .goto('https://pageThatRequireToLoginThenDiplayJsonAsText.com') 
    .wait(25000) 
    .evaluate(function (page, done) { 

    document.documentElement 
    done() 
    }) 
    .end() 
    .then(function (result) { 
    // fs.writeFileSync('testOutput.json', JSON.stringify(result)); 
    console.log(JSON.stringify(result)) 
    }) 
    .catch(function (error) { 
    console.error('failed:', error); 
    }); 
関連する問題