如何使用Python Request发送Cookie?

时间:2019-07-30 20:21:19

标签: cookies request

我正在尝试向Medium Blog网站进行request.get,但是当我打印其内容时,我收到了Cloudflare错误消息,提示它需要Cookie。那么我将如何发送cookie到Python Request?我正在使用下面的代码。

import requests

headers = {
    'authority': 'medium.com',
    'cache-control': 'max-age=0',
    'upgrade-insecure-requests': '1',
    'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/75.0.3770.142 Safari/537.36',
    'accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3',
    'accept-encoding': 'gzip, deflate, br',
    'accept-language': 'en-US,en;q=0.9,zh-CN;q=0.8,zh;q=0.7,zh-HK;q=0.6',
}

params = (
    ('format', 'json'),
)

session = requests.Session()
response = session.get('https://medium.com/gemini/latest', headers=headers, params=params)

print (response.content)

但是,输出显示

请启用cookie。\ n \ n \ n再执行一步\ n请完成安全性检查,以访问medium.com

任何帮助表示赞赏。谢谢

0 个答案:

没有答案