在请求中使用Cookie [英] Using cookie with request

查看:97
本文介绍了在请求中使用Cookie的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试发送带有URL的Cookie进行请求.但是我没有输出.代码:

I am trying to send cookie with URL for request. But I am getting no output. The code:

header ={('cookies','ecrZipInput=55401')}
response = requests.get('www.url.com', cookie=header)
soup = BeautifulSoup(response.text)

推荐答案

您可以改用这种方式:

response = requests.get('www.url.com', cookies={'ecrZipInput':'55401'})
soup = BeautifulSoup(response.text)

请注意,参数名称为 plural 'cookies',并且它接受字典值.

Notice that the parameter name is plural 'cookies' and it accepts dictionary value.

[请参阅: Requests快速入门> Cookies ]

[See : Requests Quickstart > Cookies]

这篇关于在请求中使用Cookie的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆