脚本Python版本2.7
1 #!/usr/bin/python 2 #-*- coding:utf-8 -*- 3 import os,sys 4 import time 5 import sys 6 import pycurl 7 URL="http://www.tianler.com" 8 c = pycurl.Curl() 9 c.setopt(pycurl.URL,URL) 10 c.setopt(pycurl.CONNECTTIMEOUT,5) 11 c.setopt(pycurl.TIMEOUT,5) 12 c.setopt(pycurl.NOPROGRESS,1) 13 c.setopt(pycurl.FORBID_REUSE,1) 14 c.setopt(pycurl.MAXREDIRS,1) 15 indexfile = open(os.path.dirname(os.path.realpath(__file__))+"/content.txt","wb") 16 c.setopt(pycurl.DNS_CACHE_TIMEOUT,30) 17 c.setopt(pycurl.WRITEHEADER,indexfile) 18 c.setopt(pycurl.WRITEDATA,indexfile) 19 c.setopt(pycurl.URL,URL) 20 c.setopt(pycurl.URL,URL) 21 try: 22 c.perform() 23 except Exception,e: 24 print"connection error:"+str(e) 25 indexfile.close() 26 c.close() 27 sys.exit() 28 NAMELOOKUP_TIME = c.getinfo(c.NAMELOOKUP_TIME) 29 CONNECT_TIME = c.getinfo(c.CONNECT_TIME) 30 PRETRANSFER_TIME = c.getinfo(c.PRETRANSFER_TIME) 31 STARTTRANSFER_TIME = c.getinfo(c.STARTTRANSFER_TIME) 32 TOTAL_TIME = c.getinfo(c.TOTAL_TIME) 33 HTTP_CODE = c.getinfo(c.HTTP_CODE) 34 SIZE_DOWNLOAD = c.getinfo(c.SIZE_DOWNLOAD) 35 HEADER_SIZE = c.getinfo(c.HEADER_SIZE) 36 SPEED_DOWNLOAD = c.getinfo(c.SPEED_DOWNLOAD) 37 print "HTTP状态码:%s"%(HTTP_CODE) 38 print "DNS解析时间:%.2f ms"%(NAMELOOKUP_TIME*1000) 39 print "建立连接时间:%.2f ms"%(CONNECT_TIME*1000) 40 print "准备传输时间:%.2f ms"%(PRETRANSFER_TIME*1000) 41 print "传输开始时间:%.2f ms"%(STARTTRANSFER_TIME*1000) 42 print "传输结束总时间:%.2f ms"%(TOTAL_TIME*1000) 43 print "下载数据包大小:%d bytes/s"%(SIZE_DOWNLOAD) 44 print "HTTP头部大小:%d bytes"%(HEADER_SIZE) 45 print "平均下载速度:%d bytes/s"%(SPEED_DOWNLOAD)
相信梦想是价值的源泉,相信眼光决定未来的一切,相信成功的信念比成功本身更重要,相信人生有挫折没有失败,相信生命的质量来自决不妥协的信念!——I`m geek!