问题
How can I get 3rd party cookies from website using puppeteer?
For first party I know I can use
await page.cookies()
回答1:
I was interested to know the answer so have found a solution too, it works for the current versions of Chromium 75.0.3765.0 and puppeteer 1.15.0 (updated May 2nd 2019).
Using internal puppeteer page._client
methods we can make use of Chrome DevTools Protocol directly:
(async() => {
const browser = await puppeteer.launch({});
const page = await browser.newPage();
await page.goto('https://stackoverflow.com', {waitUntil : 'networkidle2' });
// Here we can get all of the cookies
console.log(await page._client.send('Network.getAllCookies'));
})();
In the object returned there are cookies for google.com and imgur.com which we couldn't have obtained with normal browser javascript:
来源:https://stackoverflow.com/questions/50252943/puppeteer-get-3rd-party-cookies