Python 获取手机网页 Cookie 代码示例

本文提供 Python 代码示例,展示如何使用 requests 库获取手机网页的 Cookie。

import requests

# 设置请求头
headers = {
    'User-Agent': 'Mozilla/5.0 (iPhone; CPU iPhone OS 11_0 like Mac OS X) AppleWebKit/604.1.38 (KHTML, like Gecko) Version/11.0 Mobile/15A372 Safari/604.1'
}

# 发送请求
url = 'https://m.baidu.com'
response = requests.get(url, headers=headers)

# 获取cookie
cookie = response.cookies.get_dict()
print(cookie)

该代码使用 requests 库发送请求,并设置请求头模拟 iPhone 的 User-Agent,然后通过 response.cookies.get_dict() 获取 Cookie。你可以将 url 替换为你需要获取 Cookie 的网页地址。

Python 获取手机网页 Cookie 代码示例

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

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