1

module: https://www.npmjs.com/package/request

I am trying to log in on multiple accounts on a website at the same time. So to keep track of each session I am going to create an object in which I will store each account's associated cookies.

Now, how do I store the collected cookies in a variable?

   var request = require('request');
   var request = request.defaults({jar: true, headers: eo.data.headers});

   request.post(options, (err, res, body) => {
               var cookies = *SOMETHING* 
               //How do I save the cookies after I have succesfully logged into the website
Ryan Cameron
  • 371
  • 1
  • 4
  • 14
  • just save cookies in js is your problem? for save cookies in js see: https://www.w3schools.com/js/js_cookies.asp – morteza ataiy Aug 19 '18 at 13:40
  • 1
    Possible duplicate of [Get and Set a Single Cookie with Node.js HTTP Server](https://stackoverflow.com/questions/3393854/get-and-set-a-single-cookie-with-node-js-http-server) – Martín Zaragoza Aug 19 '18 at 14:06

1 Answers1

1

Try this:

const jar = request.jar();
const cookies = res.headers['set-cookie'] || [];
cookies.forEach(c => {
    jar.setCookie(c2, <that_url>);
});

Save jar to array or something you can get it.

hong4rc
  • 3,999
  • 4
  • 21
  • 40