Игла не следует за редиректом - PullRequest
0 голосов
/ 08 ноября 2018

В nodejs есть код. Код использует Nightmare для получения куки, а затем передает их neelde. В игле я пытаюсь добраться до страницы, но если я сохраняю страницу, содержащую через fs, я получаю страницу со статусом 302. Как получить нужную мне страницу?

  let proxied = Nightmare({
switches: {
  'proxy-server': proxy // set the proxy server here ...
},
show: true });

proxied
.goto(url)
.wait('input[id="id_username"]')
.insert('#id_username', loginData.login)
.insert('#id_password', loginData.pass)
.click('input[type="submit"]')
.wait('.table')
.cookies.get()
.end()
.then(function (c) {
  let u = 'https://supply.elfmoney.ru/';

  let options = {
    'cookies': {},
    'proxy': proxy,
    'follow_max': 5,
    'follow': 5
    // 'follow_set_cookies': true,
    // 'follow_set_referer': true
  };
  for (let i = 0; i < c.length; i++) {
    options['cookies'][c[i]['name']] = c[i]['value'];
  }

  needle.get(u, options, function (err, resp, body) {
    if (err) return l(err, ' while needling');
    l(resp.headers)
  });
});

Параметры для иглы, такие как «follow», «follow_max» не помогают.

UPD: я решил свою проблему. Я установил другой модуль - запрос. Поставь свои варианты как

{
    'url': u,
    'proxy': 'http://' + proxy, // proxy in format '1.1.1.1:2'
    'followAllRedirects': true,
    'headers': {
      'Cookie': cookie // cookies recieved from Nightmare executing turned to a string
    }
  }
...