I am using the following code to get the cookieID of a specific website:
var request = require('request');
var Cookie = require('request-cookies').Cookie;
request.get('http://dmp.theadex.com/d/753/i/2.gif', function(err, response, body) {
var rawcookies = response.request.headers['set-cookie'];
//console.log(response.headers);
for (var i in rawcookies) {
var cookie = new Cookie(rawcookies[i]);
//console.log(cookie.key, cookie.value);
}
}).on('redirect', function () {
let a = this.response.headers['set-cookie'];
//console.log(_.isArray(a));
console.log('a = ', a);
let cookieText = a[0];
//console.log('cookieText', cookieText);
let split = cookieText.split("'");
console.log('split = ', split[0].split(";")[0]);
});
The output is the following: a= [ 'axd=1001413541554540210; expires=Thu, 24-May-2018 13:54:54 GMT; Max-Age=31536000; path=/; domain=.theadex.com' ] split= axd=1001413541554540210
So the code is working as it should, but extracting the cookieID from the array (a) is not that efficient I guess. Does anyone have a better solution to get around this(maybe a module or a handy feature)? Thanks in advance.
via Abdulrazzak Tujjar
No comments:
Post a Comment