代码:

# -*- coding: utf-8 -*-

import urllib,urllib2,re
from random import choice
from scrapy.selector import Selector #特稳定IP 107.151.152.218:80
#http://www.xicidaili.com/wn/测试可用IP '107.151.136.202:80',222.124.130.34:8080,'103.14.196.74:8080','107.151.142.114:80''54.169.238.128:9999'
#agent = ['49.113.101.167:8090','113.78.28.205:8090','219.136.31.16:8090','119.131.83.227:8090','221.221.206.208:8090','116.52.16.57:8090','182.109.80.149:9000','59.55.59.41:9000','115.223.201.206:9000']
agent = ['107.151.136.194:80']
proxy= choice(agent)
#urllib2.ProxyHandler({'http': 'http://%s/' % proxy}) #content = urllib2.urlopen('http://www.ip.cn/').read()#111.192.249.170 handlers = [urllib2.ProxyHandler({'http': 'http://%s/' % proxy})]
opener = urllib2.build_opener(*handlers)
#opener = urllib2.build_opener()
content = opener.open(urllib2.quote('http://www.ip.cn/', safe=":/"), timeout=30).read() sel = Selector(text=content, type="html")
ip = sel.re(u'<code>\s*(.*)\s*</code>') print ip

使用代理IP地址成功的时候会显示使用的代理IP地址,或者显示timeout以及链接错误。

完毕。

最新文章

  1. 使用maven搭建ssh框架
  2. 【转】Controllers and Routers in ASP.NET MVC 3
  3. Backbone 学习笔记
  4. Android UI 绘制过程浅析(四)draw过程
  5. Android入门(二十)HttpURLConnection与HttpClient
  6. 使用cocoapods导入第三方类库后 头文件没有代码提示?
  7. android Notification 的使用
  8. IOS pop使用代理传值
  9. 【Java】理解 UDDI 注册中心的 WSDL
  10. The 2015 China Collegiate Programming Contest Game Rooms
  11. Linux 结束占用端口的程序
  12. dpkg -P &lt;pkg&gt;
  13. 我是如何处理大并发量订单处理的 KafKa部署总结
  14. iis7 安装laravel5.4环境
  15. little bird
  16. NTP 时间同步协议
  17. 嵌入式linux------ffmpeg移植 解码H264(am335x解码H264到yuv420并通过SDL显示)
  18. WPF自学入门(六)WPF带标题的内容控件简单介绍
  19. Android简易实战教程--第三十七话《NotifiCation》
  20. 使用Elasticsearch-dump迁移ES数据

热门文章

  1. 无向连通图求割边+缩点+LCA
  2. The golden ratio: 1.618
  3. nyist 597 完数?
  4. Hibernate二进制或大文件类型数据和Oracle交互
  5. HDU 4063 Aircraft(计算几何)(The 36th ACM/ICPC Asia Regional Fuzhou Site —— Online Contest)
  6. com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException
  7. javascript中字符串格式json如何转化成json对象
  8. html规范总结
  9. JS判断checkbox至少选择一项
  10. python时间处理函数