gpt4 book ai didi

javascript - 请求模块 : how do I store the collected cookies in a variable?

转载 作者:行者123 更新时间:2023-11-30 20:15:57 25 4
gpt4 key购买 nike

模块:https://www.npmjs.com/package/request

我试图同时登录网站上的多个帐户。因此,为了跟踪每个 session ,我将创建一个对象,我将在其中存储每个帐户的关联 cookie。

现在,如何将收集到的 cookie 存储在变量中?

   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

最佳答案

试试这个:

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

jar 保存到数组或您可以获得的其他内容。

关于javascript - 请求模块 : how do I store the collected cookies in a variable?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51918212/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com