(3 week Post) Puppeteer Set Cookies

Posted:   July 18, 2020

Status:   Completed

Categories :   爬虫

Were equations, pictures or diagrams not properly rendered, please refresh the page. If the problem persists, you can contact me.

题外话

唐代 许浑《赠别》

门外若无南北路,人生应免离别苦。

page.setCookie

使用插件 EditThisCookie 获取cookies各个项目内容

[{
"domain": ".renren.com",
"expirationDate": 1626122968.576495,
"hostOnly": false,
"httpOnly": false,
"name": "_de",
"path": "/",
"sameSite": "unspecified",
"secure": false,
"session": false,
"storeId": "0",
"value": "xxxxxxxxx",
"id": 1
},
.........
{
"domain": "photo.renren.com",
"hostOnly": true,
"httpOnly": false,
"name": "JSESSIONID",
"path": "/",
"sameSite": "unspecified",
"secure": false,
"session": true,
"storeId": "0",
"value": "xxxxxxxxx",
"id": 17
}]

EditThisCookie中获取的cookies有些项在setCookie中没有,剔除多余项。

sameSite <"Strict"|"Lax">, 只能二选一

const cookie = [
{
    "domain": ".renren.com",
    "expires": 1626122968.576495,
    "httpOnly": false,
    "name": "_de",
    "path": "/",
    "sameSite": "Lax",
    "secure": false,
    "value": "xxxxxxxxx",
},
.....
{
    "domain": "photo.renren.com",
    "httpOnly": false,
    "name": "JSESSIONID",
    "path": "/",
    "sameSite": "Lax",
    "secure": false,
    "value": "xxxxxxxxx",
}
const promise = await page.setCookie(...cookie);

Comments


Be the first one to comment on this page!
You can use extended GitHub flavored markdown in your comment. Commenting FAQs & Guidelines