Python创建cookie,然后加载一个带有cookie的页面 [英] Python create cookies and then load a page with the cookies

查看:91
本文介绍了Python创建cookie,然后加载一个带有cookie的页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我想从一个python程序访问一个网页。
我必须设置cookie来加载页面。

我使用httplib2库,但我没有找到如何添加我自己的cookie

  resp_headers,content = h.request(http://www.theURL.com,GET)
pre>

如何创建具有正确名称和值的cookie,将其添加到函数然后加载页面?

感谢

解决方案

  http = httplib2.Http()
#get cookie_value here
headers = {'Cookie':cookie_value}
response,content = http.request(http://www.theURL.com,'GET',headers = headers)

您可能需要添加其他标头参数以指定其他HTTP请求参数。



I would like to access a web page from a python program. I have to set up cookies to load the page.
I used the httplib2 library, but I didn't find how add my own cookie

resp_headers, content = h.request("http://www.theURL.com", "GET")

How can I create cookies with the right name and value, add it to the function and then load the page?
Thanks

解决方案

http = httplib2.Http()
# get cookie_value here
headers = {'Cookie':cookie_value}
response, content = http.request("http://www.theURL.com", 'GET', headers=headers)

You may want to add another header parameters to specify another HTTP request parameters.

这篇关于Python创建cookie,然后加载一个带有cookie的页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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