Python script to test Web page speed

Source: Internet
Author: User
Tags python script

First, test Web page Speed script

[[email protected] ~]# cat check_url.py #!/usr/bin/python# Coding:utf-8import 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 response status:%d '%http_code print ' DNS resolution time:%.2f MS '% (dns_resolve*1000) print ' Established connection time:%.2f ms '% (htt    p_conn_time*1000) print ' Ready to transfer time:%.2f MS '% (http_pre_trans*1000) print "Transfer start time:%.2f ms"% (http_start_trans*1000) Print "Transfer end time:%.2f MS"% (http_total_time*1000) print "Download packet size:%d bytes/s"%http_size_download print "HTTP header size:%d BYTES/S "%http_header_size print" average download speed:%d k/s "% (http_speed_downlaod/1024) if __name__ = = ' __main__ ': Input_url = Sys.argv[1] Test_gzip (Input_url)

#授执行权限并运行脚本

#授执行权限 [[email protected] ~]# chmod +x check_url.py #运行脚本 [[email protected] ~]# python check_url.py www.baidu.comHTTP response status: 200DNS resolution Time: 41.01 MS Establish connection time: 62.14 Ms ready to transfer time: 62.57 MS Transfer start: 120.10 MS Transfer end time: 126.41 ms download Packet size: 32007 bytes/shttp header size: 965 b ytes/s average download speed: 247 k/s

  

Python script to test Web page speed

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.