[email protected] mnt]# cat pycurl.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 response status:%d '%http_code
print ' DNS resolution time:%.2f MS '% (dns_resolve*1000)
print ' Establish connection time:%.2f ms '% (http_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] mnt]# chmod 755 pycurl.py
[email protected] mnt]# python prl.py www.huanqiu.com
HTTP response Status: 200
DNS resolution time: 5514.43 MS
Established connection time: 5735.63 ms
Ready for transfer time: 5735.78 MS
Transfer start time: 6558.61 ms
Transfer end time: 6797.67 MS
Download packet size: 40732 bytes/s
HTTP Header size: 361 bytes/s
Average download speed: 5 k/s
[email protected] mnt]# python prl.py www.baidu.com
HTTP response Status: 200
DNS resolution time: 509.20 MS
Established connection time: 548.33 ms
Ready for transfer time: 548.45 MS
Transfer start time: 589.60 ms
Transfer end time: 591.98 MS
Download packet size: 27132 bytes/s
HTTP Header size: 1031 bytes/s
Average download speed: k/s
A simple Python script to test Web page speed