网上找的免费代理ip
#!/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()