2

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()

})

after saving the cookies into the file, it saves multiple cookies dictionary in file

[ { "name": "_gat", "value": "1", "domain": "www.google.com", "path": "/", "expires": 1582024891, "size": 5, "httpOnly": false, "secure": false, "session": false }, { "name": "_gid", "value": "GA1.2.1936512649.1582024831", "domain": "www.google.com", "path": "/", "expires": 1582111231, "size": 31, "httpOnly": false, "secure": false, "session": false }, { "name": "_ga", "value": "GA1.2.1830413277.1582024831", "domain": "www.google.com", "path": "/", "expires": 1645096831, "size": 30, "httpOnly": false, "secure": false, "session": false }, { "name": "__cfduid", "value": "d9ccc472957afbae818db60dff47cc5e01582024830", "domain": "www.google.com", "path": "/", "expires": 1584616830.613503, "size": 51, "httpOnly": true, "secure": true, "session": false, "sameSite": "Lax" } ]

I am not able to decide which one should use for making a request in the python-requests module?

abhay kumar
  • 83
  • 1
  • 10
  • why not just send all of them? – mbit Feb 18 '20 at 17:22
  • the python-requests library doesn't support the list as cookies. – abhay kumar Feb 20 '20 at 05:57
  • you don't need to pass the list, that list is basically equivalent of dict of key values. python's requests supports multiple cookies key values https://stackoverflow.com/questions/42801680/python-requests-send-multiple-cookies – mbit Feb 20 '20 at 08:20
  • also each key value plays a different role, and it's not your job to determine which cookies are useful/related to the functionality you want, websites define that. you should just behave like a browser and send any cookie in the cookie jar that match the domain/path and flags. – mbit Feb 20 '20 at 08:30
  • yes, you are right I got the answer, you saying it right passing all cookies using list is working correctly right now. – abhay kumar Nov 14 '20 at 05:02
  • @abhaykumar would you mind how you converted the puppeteer cookies to a list for requests? I'm not able to directly use the saved puppeteer cookies – Clinton Sorrel May 10 '21 at 22:23

0 Answers0