获取 Cookie 的方法因网站而异,一般有以下几种方法:

  1. 登录网站后,在浏览器中按 F12 打开开发者工具,在 Network 或 Application 标签下找到对应的请求,可以在 Headers 或 Cookies 中找到 Cookie。

  2. 使用浏览器插件,如 EditThisCookie、Cookie Editor 等,可直接查看和编辑 Cookie。

  3. 使用 Python 的 requests 库发送请求时,可以在请求头中加入 Cookie,例如:

import requests

url = 'https://www.example.com'
headers = {
    'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.36',
    'Cookie': 'key1=value1; key2=value2',  # 将 Cookie 字符串写入请求头
    'Referer': url
}

response = requests.get(url, headers=headers)

其中,key1=value1; key2=value2 是 Cookie 字符串。可以在浏览器中找到 Cookie,复制后粘贴到代码中即可

headers = User-Agent Mozilla50 Windows NT 100; Win64; x64 AppleWebKit53736 KHTML like Gecko Chrome5803029110 Safari53736 Cookie 你的Cookie Referer url 这段代码中应怎样获得cookie

原文地址: https://www.cveoy.top/t/topic/g7qe 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录