如何从puppeteer中保存cookie并使用cookie在python中发出请求?

时间:2020-02-18 11:33:55

标签: python node.js puppeteer


const puppeteer = require('puppeteer-extra')
// add stealth plugin and use defaults (all evasion techniques)
const StealthPlugin = require('puppeteer-extra-plugin-stealth')
puppeteer.use(StealthPlugin())


puppeteer.launch({ headless: true,ignoreHTTPSErrors:true, args: [ '--no-sandbox', '--proxy-server=51.158.111.242:8811' ] }).then(async browser => {


console.log('Running tests..')

const page = await browser.newPage()

await page.goto('https://google.com/')

const cookies = await page.cookies();

console.log(cookies);

await fs.writeFile('./cookies.json', JSON.stringify(cookies, null, 2));

await page.screenshot({ path: 'testresult.png', fullPage: true })

await browser.close()

})

将cookie保存到文件中后,它将多个cookie字典保存在文件中

[ { “ name”:“ _gat”, “ value”:“ 1”, “ domain”:“ www.google.com”, “ path”:“ /”, “到期”:1582024891, “大小”:5 “ httpOnly”:否, “安全”:错误, “会话”:false }, { “ name”:“ _gid”, “值”:“ GA1.2.1936512649.1582024831”, “ domain”:“ www.google.com”, “ path”:“ /”, “过期”:1582111231, “大小”:31, “ httpOnly”:否, “安全”:错误, “会话”:false }, { “ name”:“ _ga”, “值”:“ GA1.2.1830413277.1582024831”, “ domain”:“ www.google.com”, “ path”:“ /”, “过期”:1645096831, “大小”:30, “ httpOnly”:否, “安全”:错误, “会话”:false }, { “ name”:“ __cfduid”, “值”:“ d9ccc472957afbae818db60dff47cc5e01582024830”, “ domain”:“ www.google.com”, “ path”:“ /”, “到期”:1584616830.613503, “大小”:51, “ httpOnly”:是的, “安全”:是的, “会话”:false, “ sameSite”:“宽松” } ]

我无法在python-requests模块中决定应该使用哪个请求?

0 个答案:

没有答案