简体   繁体   中英

How to set cookies with pyppeteer

I know barely anything about cookies, but I need to set them in order to make my program work. Let's say I have these cookies:

 "fl-test-cookie-exist=Exist; fl-notice-cookie=true; country_notify=true; _svtri=6b01b3be-4fe8-4b91-8282-1613818f3329; _ga=GA1.2.842004217.1579404024; _fbp=fb.1.1579404024541.600339844; scarab.visitor=%226461D28971E3E0BA%22; _hjid=b601b76b-f122-4ba9-9a8c-d6fcdf5f368e; _crbx=b3b2745b-8fb4-4cb8-bd34-c69f479d1cfa; __zlcmid=wKiqd1GkJlTkIi; fita.sid.footlocker_eu=6k4vL-qyM8JRJG2CFSe2sm6brf9WYjz3; OptanonAlertBoxClosed=2020-01-19T03:48:01.217Z; _abck=C64424015AC0B0105676118215BC44C2~0~YAAQdAIkF11dnoJuAQAALofruwNEbc5wL+ZOWzzIFS8amV/qlm6lkf29ulMcoZEzJfnOdRYu0CrNf3+ja0SbwdkPslNfvAcIITMBBGg77CNWOPLcQqIUWKOvLU3EmFbhANnkXICl0Ch3Lbu2pD1e3rJtf8Q/QzbJmAt/gX8PrqrovJfn9wLtyGR+vDE1sEXOB/yYuOeik5M+0oyJUrQRPm698nUWdZ1oVqJd88OGwVpOmE2rmN+kFJhb1qOPMJBZlsMvAxDj1niiMfBWEJvrb4mIpf7vDD4uaz/TkJ7z7OB/uaOqNo7x7o1P1EwLjPizMmgvujjwL5i5xQ==~-1~-1~-1; sto-id-47873=ALPOBFKMPOCA; check=true; mboxEdgeCluster=28; mbox=PC#e6cd0cbb3290401490c41788f9eacc1d.28_0#1643685841|session#b5eae18e8bbd49fba332e7b053220170#1580442897; OptanonConsent=landingPath=NotLandingPage&datestamp=Thu+Jan+30+2020+19%3A24%3A00+GMT-0800+(Pacific+Standard+Time)&version=3.6.25&groups=1%3A1%2C2%3A1%2C3%3A1%2C4%3A1%2C101%3A1%2C102%3A1%2C103%3A1&AwaitingReconsent=false; _svlet=1580441040982; _gid=GA1.2.670261469.1580441041; scarab.mayAdd=%5B%7B%22i%22%3A%22314100494104%22%7D%5D; _svs=%7B%22p%22%3A%7B%220%22%3A1580441037477%2C%227%22%3A1580441037478%7D%2C%22c%22%3A%7B%221%22%3Atrue%2C%222%22%3Atrue%2C%223%22%3Atrue%2C%224%22%3Atrue%7D%2C%22ct%22%3A1580441044719%2C%22e%22%3A%7B%2225%22%3A%7B%22group%22%3A27%2C%22sent%22%3Atrue%7D%7D%7D"

and I have to set them with pyppeteer ( https://miyakogi.github.io/pyppeteer/reference.html#page-class ), now I already split the cookies up with SimpleCookie and I converted the cookies into a dictionary.

My question is: what is supposed to go in all those field (name and value) which of those would be the name and which would be the value? I have multiple cookies, so how do I set them all?

Thank you in advance <3

You can set cookie for page with:

await page.setCookie(*cookie)

Where cookie is a list containing python dict with the cookie you have there. You have to turn it into python dict. Result should be list like this:

cookie = [{'fl-test-cookie-exist':'Exist',
         'fl-notice-cookie'= True,
         'country_notif': True,
         ... }]

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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