1. 程式人生 > >python教程

python教程

install some python ole response 設置代理 sso name for

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

python教程