繁体   English   中英

'Set-Cookie' 不包含在响应头中

[英]'Set-Cookie' is not included in the response headers

我正在尝试从 http 响应中获取set-cookie标头,但它没有出现在大多数请求中。

https://www.southwest.com/为例,可以看到https://bs.serving-sys.com/Serving/ActivityServer.bs?cn=as&ActivityID=1345510&rnd=459203.51759912557&fare%20class=[fare%20class]&business%20or%20leisure=[business%20or%20leisure]&number%20of%20passengers=[number%20of%20passengers]&date=[date]&destination=[destination]&origination=[origination]设置 3 个 cookie: 在此处输入图片说明

傀儡师代码:

const puppeteer = require('puppeteer');

async function getResponseCookies() {
    function handleResponse(response) {
        const url = response.url();
        const headers = response.headers();
        const status = response.status()

        if(url.includes('https://bs.serving-sys.com/Serving/ActivityServer.bs')) {
            console.log('RESPONSE URL ', url)
            console.log('RESPONSE HEADERS ', headers)
            console.log('RESPONSE STATUS ', status)
        }
    }

    const browser = await puppeteer.launch({
        ignoreDefaultArgs: ["--enable-automation"],
        executablePath: "/usr/bin/google-chrome",
        headless: true,
        ignoreHTTPSErrors: true,
    });

    const page = await browser.newPage();

    await page.setUserAgent("Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.130 Safari/537.36");

    await page.on('response', async(response) => {
        await handleResponse(response);
    })

    const urls = ['https://www.southwest.com'];

    for(let url of urls) {
        await page.goto(url, { timeout: 0, waitUntil: 'networkidle0' });
    }
    await browser.close();
}

getResponseCookies();

上面的代码执行输出以下日志,响应中没有任何“set-cookie”标头:

RESPONSE URL  https://bs.serving-sys.com/Serving/ActivityServer.bs?cn=as&ActivityID=1345510&rnd=68456.37277058625&fare%20class=[fare%20class]&business%20or%20leisure=[business%20or%20leisure]&number%20of%20passengers=[number%20of%20passengers]&date=[date]&destination=[destination]&origination=[origination]
RESPONSE HEADERS  { pragma: 'no-cache',
  date: 'Mon, 03 Feb 2020 10:30:16 GMT',
  'content-encoding': 'gzip',
  server: 'Microsoft-IIS/7.5',
  'x-powered-by': 'ASP.NET',
  p3p: 'CP="NOI DEVa OUR BUS UNI"',
  'access-control-allow-origin': '*',
  'cache-control': 'no-cache, no-store',
  'content-type': 'text/html; charset=UTF-8',
  'content-length': '616',
  expires: 'Sun, 05-Jun-2005 22:00:00 GMT' }

任何想法为什么响应中缺少Set-Cookie标头?

*请注意,使用CDP 中的Network.getAllCookies时会返回这些 cookie

根据https://github.com/puppeteer/puppeteer/issues/4918 ,看起来 puppeteer 没有侦听包含原始标头的 Network.responseReceivedExtraInfo 事件。 听那个事件对我有用。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM