'''
无忧代理IP Created on 2016年12月23日
@author: www.data5u.com
'''
import urllib;
import random
if __name__ == '__main__':
order = "888888888888888";
apiUrl = "http://api.ip.data5u.com/dynamic/get.html?order=" + order;
targetUrl = "http://1212.ip138.com/ic.asp";
try:
res = urllib.urlopen(apiUrl).read().strip("\n");
ips = res.split("\n");
proxyip = random.choice(ips)
html = urllib.urlopen(targetUrl, proxies={'http':'http://' + proxyip})
print("使用代理IP " + proxyip + " 获取到如下HTML内容:\n" + unicode(html.read(), "gb2312").encode("utf8"))
except Exception,e:
print(e)