Загрузите JSON за страницей входа с кошмаром

Я пытаюсь скачать тяжелый JSON, который находится за страницей входа. Документ составляет около 5 МБ и занимает примерно 60 секунд для загрузки моего соединения. Я попробовал этот код, но в результате у меня остается пустой объект. Есть идеи, в чем проблема? Спасибо!

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

1 ответ

Решение

Нашел ответ. По сути, мне просто пришлось загрузить второй раз 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);
  });
Другие вопросы по тегам