您可以做几件事:
- 构建自己的HTTPRedirectHandler来拦截每个重定向
- 创建HTTPcookieProcessor的实例并安装该打开程序,以便您可以访问cookiejar。
这是一件快速的小事,既显示了
import urllib2#redirect_handler = urllib2.HTTPRedirectHandler()class MyHTTPRedirectHandler(urllib2.HTTPRedirectHandler): def http_error_302(self, req, fp, pre, msg, headers): print "cookie Manip Right Here" return urllib2.HTTPRedirectHandler.http_error_302(self, req, fp, pre, msg, headers) http_error_301 = http_error_303 = http_error_307 = http_error_302cookieprocessor = urllib2.HTTPcookieProcessor()opener = urllib2.build_opener(MyHTTPRedirectHandler, cookieprocessor)urllib2.install_opener(opener)response =urllib2.urlopen("WHEReEVER")print response.read()print cookieprocessor.cookiejar
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)