網上找的免費代理ippython
#!/usr/bin/env python # -*- coding:utf-8 -*- import urllib2 # 代理開關 proxyswitch = True # Handler代理對象,dict類型 httpproxy_handler = urllib2.ProxyHandler({"http": "119.52.247.13:8080"}) # 無代理Handler代理對象 nullproxy_handler = urllib2.ProxyHandler({}) if proxyswitch: opener = urllib2.build_opener(httpproxy_handler) else: opener = urllib2.build_opener(nullproxy_handler) # 全局opener,以後全部的請求均可以用urlopen(去發送,也附帶Handler的功能 urllib2.install_opener(opener) request = urllib2.Request("http://www.baidu.com") reponse = urllib2.urlopen(request) # print reponse.read().decode("gbk") print reponse.read()