#-*-coding:utf-8-*-#@Author: Felix Wang#@time: 2018/8/13 22:13#PIP3 Install PycurlImportPycurl fromIoImportBytesiodeftest_website (URL): C=Pycurl. Curl () Buffer= Bytesio ()#Create a Cache objectC.setopt (c.writedata, buffer)#to set the resource data to be written to the cache objectC.setopt (C.url, URL)#Specify the requested URLC.setopt (C.maxredirs, 5)#Specify the maximum number of HTTP redirectsC.perform ()#ExecutionHttp_code= C.getinfo (Pycurl. HTTP_CODE)#the HTTP status code returnedDns_resolve = C.getinfo (pycurl. Namelookup_time)#time consumed by DNS resolutionHttp_conn_time = C.getinfo (pycurl. Connect_time)#time spent establishing a connectionHttp_pre_trans = C.getinfo (pycurl. Pretransfer_time)#the time consumed from establishing the connection to preparing the transferHttp_start_trans = C.getinfo (pycurl. Starttransfer_time)#the time from when the connection was established to the start of the transferHttp_total_time = C.getinfo (pycurl. Total_time)#total time consumed by transfer endHttp_size_download = C.getinfo (pycurl. Size_download)#Download Packet sizeHttp_size_upload = C.getinfo (pycurl. Size_upload)#Upload Packet sizeHttp_header_size = C.getinfo (pycurl. Header_size)#HTTP Header SizeHttp_speed_downlaod = C.getinfo (pycurl. Speed_download)#Average Download speedHttp_speed_upload = C.getinfo (pycurl. Speed_upload)#Average upload speedHttp_redirect_time = C.getinfo (pycurl. Redirect_time)#time spent in redirection Print('HTTP response Status:%d'%http_code)Print('DNS resolution Time:%.2f MS'% (Dns_resolve * 1000)) Print('established connection time:%.2f Ms'% (Http_conn_time * 1000)) Print('Ready for 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("REDIRECT time:%.2f Ms"% (Http_redirect_time * 1000)) Print("upload packet size:%d bytes/s"%http_size_upload)Print("Download Packet size:%d bytes/s"%http_size_download)Print("HTTP Header size:%d bytes/s"%http_header_size)Print("average upload speed:%d k/s"% (http_speed_upload/1024)) Print("average download speed:%d k/s"% (http_speed_downlaod/1024))if __name__=='__main__': Test_url='www.baidu.com'test_website (Test_url)
Python test Site access speed