Python之Web业务质量检测

发表于:2016-6-28 11:15

字体: | 上一篇 | 下一篇 | 我要投稿

 作者:知_行    来源:51Testing软件测试网采编

  不知为何,也许我对pycurl模块了解不够透彻的原因吧,测出来的时间与firebug所得不同,但是firebug是对的,这点我肯定
  仍将学习到的代码贴出如下
#!/usr/local/bin/python3.5
# -*- coding: utf-8 -*-
import pycurl
import time
import os
import sys
URL = "http://xxx.xxxx.xxx.xx"
c = pycurl.Curl()
c.setopt(pycurl.URL, URL)
c.setopt(pycurl.CONNECTTIMEOUT, 5)
c.setopt(pycurl.TIMEOUT, 5)
c.setopt(pycurl.NOPROGRESS, 1)
c.setopt(pycurl.FORBID_REUSE, 1)
c.setopt(pycurl.MAXREDIRS, 1)
c.setopt(pycurl.DNS_CACHE_TIMEOUT, 30)
indexfile = open(os.path.dirname(os.path.realpath(__file__)) + "/content.txt", "wb")
c.setopt(pycurl.WRITEHEADER, indexfile)
c.setopt(pycurl.WRITEDATA, indexfile)
try:
c.perform()
except Exception as e:
print("connection error :" + str(e))
indexfile.close()
c.close()
sys.exit()
NAMELOOKUP_TIME = c.getinfo(c.NAMELOOKUP_TIME)
CONNECT_TIME = c.getinfo(c.CONNECT_TIME)
PRETRANSFER_TIME = c.getinfo(c.PRETRANSFER_TIME)
STARTTRANSFER_TIME = c.getinfo(c.STARTTRANSFER_TIME)
TOTAL_TIME = c.getinfo(c.TOTAL_TIME)
HTTP_CODE = c.getinfo(c.HTTP_CODE)
SIZE_DOWNLOAD = c.getinfo(c.SIZE_DOWNLOAD)
HEADER_SIZE = c.getinfo(c.HEADER_SIZE)
SPEED_DOWNLOAD = c.getinfo(c.SPEED_DOWNLOAD)
print("HTTP状态码:%s" % (HTTP_CODE))
print("DNS解析时间:%.2f ms" % (NAMELOOKUP_TIME*1000))
print("建立链接时间:%.2f ms" % (CONNECT_TIME*1000))
print("准备传输时间:%.2f ms" % (PRETRANSFER_TIME*1000))
print("传输开始时间:%.2f ms" % (STARTTRANSFER_TIME*1000))
print("传输结束总时间:%.2f ms" % (TOTAL_TIME*1000))
print("下载数据包大小:%d bytes/s" % (SIZE_DOWNLOAD))
print("HTTP头部大小:%d byte" % (HEADER_SIZE))
print("平均下载速度:%d bytes/s" % (SPEED_DOWNLOAD))
indexfile.close()
c.close()
  测的结果
《2023软件测试行业现状调查报告》独家发布~

关注51Testing

联系我们

快捷面板 站点地图 联系我们 广告服务 关于我们 站长统计 发展历程

法律顾问:上海兰迪律师事务所 项棋律师
版权所有 上海博为峰软件技术股份有限公司 Copyright©51testing.com 2003-2024
投诉及意见反馈:webmaster@51testing.com; 业务联系:service@51testing.com 021-64471599-8017

沪ICP备05003035号

沪公网安备 31010102002173号