如何使用pyppeteer设置cookies

2024-10-04 01:23:09 发布

您现在位置:Python中文网/ 问答频道 /正文

我对Cookie几乎一无所知,但我需要设置它们以使我的程序工作。 假设我有这些饼干:

"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"

我必须用pyppeteer(https://miyakogi.github.io/pyppeteer/reference.html#page-class)设置它们, 现在我已经用SimpleCookie将cookies拆分,并将cookies转换为字典

我的问题是:在所有这些字段(名称和值)中应该包含什么?哪些字段是名称,哪些字段是值?我有多个cookie,那么如何设置它们

提前感谢您<;三,


Tags: test程序名称truecookiecountrynoticeexist
1条回答
网友
1楼 · 发布于 2024-10-04 01:23:09

您可以使用以下设置页面的cookie:

await page.setCookie(*cookie)

其中cookie是一个包含python dict的列表,其中包含您所拥有的cookie。您必须将其转换为python dict。结果应如下所示:

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

相关问题 更多 >