2

我对 cookie 几乎一无所知,但我需要设置它们以使我的程序正常工作。假设我有这些 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 拆分了 cookie,并将 cookie 转换为字典。

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

提前谢谢你<3

4

1 回答 1

1

您可以为页面设置 cookie:

await page.setCookie(*cookie)

其中 cookie 是一个包含 python dict 的列表,其中包含您那里的 cookie。你必须把它变成python dict。结果应该是这样的列表:

cookie = [{'fl-test-cookie-exist':'Exist',
         'fl-notice-cookie'= True,
         'country_notif': True,
         ... }]
于 2020-10-14T09:02:58.147 回答