urllib2用饼干 [英] urllib2 with cookies
本文介绍了urllib2用饼干的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我试图向使用python的需要cookie的RSS提要发出请求。我认为使用urllib2和添加适当的标题就足够了,但请求仍然说不受欢迎。
I am trying to make a request to an RSS feed that requires a cookie, using python. I thought using urllib2 and adding the appropriate heading would be sufficient, but the request keeps saying unautherized.
猜测这可能是远程站点上的问题,但不能确定。如何使用urllib2和cookies?是有更好的包(例如httplib,mechanize,curl)
Im guessing it could be a problem on the remote sites' side, but wasnt sure. How do I use urllib2 along with cookies? is there a better package for this (like httplib, mechanize, curl)
推荐答案
import urllib2
opener = urllib2.build_opener()
opener.addheaders.append(('Cookie', 'cookiename=cookievalue'))
f = opener.open("http://example.com/")
这篇关于urllib2用饼干的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文