PC客户端开发研究者---爱生活,爱code!

python教程

1、http://python.jobbole.com/81361/

 

如何设置代理:

import urllib2
enable_proxy = True
proxy_handler = urllib2.ProxyHandler({"http" : 'http://some-proxy.com:8080'})
null_proxy_handler = urllib2.ProxyHandler({})
if enable_proxy:
    opener = urllib2.build_opener(proxy_handler)
else:
    opener = urllib2.build_opener(null_proxy_handler)
urllib2.install_opener(opener)

 

如何显示cookie

 cookie = cookielib.CookieJar()
 handler = urllib2.HTTPCookieProcessor(cookie)
 opener = urllib2.build_opener(handler)
 response = opener.open('http://www.baidu.com')
 for item in cookie:
     print 'Name = ' + item.name
     print 'Value = ' + item.value

 

posted @ 2017-09-17 00:57  xxiaoye  阅读(196)  评论(0编辑  收藏  举报