python测试代理IP地址
2024-09-23 08:06:48
代码:
# -*- 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以及链接错误。
完毕。
最新文章
- 使用maven搭建ssh框架
- 【转】Controllers and Routers in ASP.NET MVC 3
- Backbone 学习笔记
- Android UI 绘制过程浅析(四)draw过程
- Android入门(二十)HttpURLConnection与HttpClient
- 使用cocoapods导入第三方类库后 头文件没有代码提示?
- android Notification 的使用
- IOS pop使用代理传值
- 【Java】理解 UDDI 注册中心的 WSDL
- The 2015 China Collegiate Programming Contest Game Rooms
- Linux 结束占用端口的程序
- dpkg -P <;pkg>;
- 我是如何处理大并发量订单处理的 KafKa部署总结
- iis7 安装laravel5.4环境
- little bird
- NTP 时间同步协议
- 嵌入式linux------ffmpeg移植 解码H264(am335x解码H264到yuv420并通过SDL显示)
- WPF自学入门(六)WPF带标题的内容控件简单介绍
- Android简易实战教程--第三十七话《NotifiCation》
- 使用Elasticsearch-dump迁移ES数据
热门文章
- 无向连通图求割边+缩点+LCA
- The golden ratio: 1.618
- nyist 597 完数?
- Hibernate二进制或大文件类型数据和Oracle交互
- HDU 4063 Aircraft(计算几何)(The 36th ACM/ICPC Asia Regional Fuzhou Site —— Online Contest)
- com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException
- javascript中字符串格式json如何转化成json对象
- html规范总结
- JS判断checkbox至少选择一项
- python时间处理函数