# coding: utf-8

 import urllib2
import re
import time def getDL(page):
url = 'http://www.xicidaili.com/nt/{}'.format(page)
header = {
'User-Agent':'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/61.0.3163.100 Safari/537.36'
} req=urllib2.Request(url, headers=header)
res=urllib2.urlopen(req)
html=res.read() srclist=re.findall(r'<tr class=(.|\n)*?<td>(\d+\.\d+\.\d+\.\d+)</td>(.|\n)*?<td>(\d+)</td>(.|\n)*?<td>(HTTP|HTTPS)</td>', html)
xlist = []
for item in srclist:
xlist.append((item[5],item[1],item[3]))
return xlist def testDL(ipstr):
proxy= urllib2.ProxyHandler({'http':"{}:{}".format(ipstr[1], ipstr[2])})
opener=urllib2.build_opener(proxy)
urllib2.install_opener(opener) try:
testUrl = 'http://httpbin.org/ip'
testUrl = 'http://2017.ip138.com/ic.asp'
req=urllib2.Request(testUrl)
res=urllib2.urlopen(req).read()
print "********************* √ {} -- {}".format(ipstr, res) with open("ok.txt","a") as f:
f.write("{} {} {}\n".format(ipstr[0], ipstr[1], ipstr[2]))
f.close()
except Exception as e:
print "******** ×, {} -- {}".format(ipstr, e)
time.sleep(1) def startTask():
for page in xrange(5):
list=getDL(page+1)
for item in list:
testDL(item) if __name__ == '__main__':
startTask()

最新文章

  1. 计算机维修之操作系统的安装(windows、Mac、Linux)
  2. Hibernate —— 检索策略
  3. DP:Making the Grade(POJ 3666)
  4. PHP中变量,常量,超级全局变量小结
  5. WinForm C#全局错误捕捉处理【整理】
  6. asp.net Hierarchical Data
  7. Supporting Multiple Screens 翻译 支持各种屏幕(上)
  8. android滑动基础篇 TouchView
  9. Android使用VideoView播放网络视频
  10. c#自带压缩类实现数据库表导出到CSV压缩文件
  11. IOS touch event animation 转动的风车
  12. 老李推荐:第2章4节《MonkeyRunner源码剖析》了解你的测试对象: NotePad窗口Activity之菜单简介
  13. conda创建py27虚拟环境安装theano(anaconda3)
  14. webpack4 splitChunksPlugin &amp;&amp; runtimeChunkPlugin 配置杂记
  15. 圈水池 nyoj 78 凸包算法
  16. 利用Python中SocketServer 实现客户端与服务器间非阻塞通信
  17. centos安装VirtualBox增强包VBoxGuestAdditions
  18. 【转】HTTP协议之multipart/form-data请求分析
  19. Python int 中 add abs 方法
  20. 前端和后端的数据交互(jquery ajax+python flask+mysql)

热门文章

  1. Script Encryption
  2. python第二天 python介绍与变量
  3. 性能测试-8.LR常用函数
  4. Python学习笔记第二十一周
  5. 11.2.0.4单实例DRCP(Database Resident Connection Pooling)简单测试
  6. C#线程、前后台线程
  7. django安装命令
  8. multi-head attention
  9. mod libs 课堂
  10. js 三目运算