测试网站页面网速的一个简单Python脚本
2016-09-05 02:32
429 查看
无聊之余,下面分享一个Python小脚本:测试网站页面访问速度
赋予脚本执行权限
测试网页,比如www.huanqiu.com
[root@huanqiu ~]# vim pywww.py #!/usr/bin/python # coding: UTF-8 import StringIO,pycurl,sys,os,time class idctest: def __init__(self): self.contents = '' def body_callback(self,buf): self.contents = self.contents + buf def test_gzip(input_url): t = idctest() #gzip_test = file("gzip_test.txt", 'w') c = pycurl.Curl() c.setopt(pycurl.WRITEFUNCTION,t.body_callback) c.setopt(pycurl.ENCODING, 'gzip') c.setopt(pycurl.URL,input_url) c.setopt(pycurl.MAXREDIRS, 5) c.perform() http_code = c.getinfo(pycurl.HTTP_CODE) dns_resolve = c.getinfo(pycurl.NAMELOOKUP_TIME) http_conn_time = c.getinfo(pycurl.CONNECT_TIME) http_pre_trans = c.getinfo(pycurl.PRETRANSFER_TIME) http_start_trans = c.getinfo(pycurl.STARTTRANSFER_TIME) http_total_time = c.getinfo(pycurl.TOTAL_TIME) http_size_download = c.getinfo(pycurl.SIZE_DOWNLOAD) http_header_size = c.getinfo(pycurl.HEADER_SIZE) http_speed_downlaod = c.getinfo(pycurl.SPEED_DOWNLOAD) print 'HTTP响应状态: %d' %http_code print 'DNS解析时间:%.2f ms' %(dns_resolve*1000) print '建立连接时间: %.2f ms' %(http_conn_time*1000) print '准备传输时间: %.2f ms' %(http_pre_trans*1000) print "传输开始时间: %.2f ms" %(http_start_trans*1000) print "传输结束时间: %.2f ms" %(http_total_time*1000) print "下载数据包大小: %d bytes/s" %http_size_download print "HTTP头大小: %d bytes/s" %http_header_size print "平均下载速度: %d k/s" %(http_speed_downlaod/1024) if __name__ == '__main__': input_url = sys.argv[1] test_gzip(input_url)
赋予脚本执行权限
[root@huanqiu ~]# chmod 755 pywww.py
测试网页,比如www.huanqiu.com
[root@huanqiu ~]# python pywww.py www.huanqiu.com HTTP响应状态: 200 DNS解析时间:2.56 ms 建立连接时间: 4.92 ms 准备传输时间: 4.93 ms 传输开始时间: 13.08 ms 传输结束时间: 17.71 ms 下载数据包大小: 40101 bytes/s HTTP头大小: 356 bytes/s 平均下载速度: 2210 k/s
相关文章推荐
- 一个简单的使用代理访问百度页面内容的python脚本
- Python自动化测试例子--一个简单的自动化测试用例脚本--批量执行测试用例
- Pexpect简单的测试——一个 expect的python实现
- JQuery Lightbox -- "一个简单而又谦恭的用来把图片覆盖在当前页面上的脚本"
- 在Python3下使用tornado和SQLAlchemy实现一个简单的MVC网站
- 一个简单的判断远端服务器端口是否通的Python脚本
- Appium自动化测试系列2- 写一个Python测试脚本来测试一下YY语音
- 一个简单的在线客服的实现(漂浮在网站左侧,随页面滚动
- 目前大家对Python都有一个共识,就是他对测试非常有用,自动化测试里Python用途也很广,但是Python到底怎么进行自动化测试呢?今天就简单的向大家介绍一下怎么使用Python进行自动化测试
- 简单shell脚本监控网站页面
- python 一个简单防攻击脚本
- 一个简单的 python 实现 图片同步脚本 ,对于有图片群集的项目有参考价值
- [python脚本]一个简单的web爬虫(1)
- 一个简单的脚本程序----Python
- Pexpect简单的测试——一个 expect的python实现
- 一个在线测试Html、脚本代码的网站!(不用建文件了)
- python写一个最简单的可执行脚本
- 网上找到一个可以用来测试网站安全性能的测试ASP页面
- 一个测试网速的网站连接
- python 一个简单的、迅速生成和执行循环的辅助脚本