#!/usr/bin/python Import Pycurl Import time Import Sys Import Os,sys Url=input ("Enter the URL want to query:\n") C=pycurl. Curl () C.setopt (Pycurl. Url,url) C.setopt (Pycurl. connecttimeout,5) # defines the number of request connections C.setopt (Pycurl. noprogress,1) # block download progress bar C.setopt (Pycurl. forbid_reuse,1) # Force Disconnect after complete interaction, no reuse C.setopt (Pycurl. maxredirs,1) # Specifies the maximum number of HTTP redirects is 1 C.setopt (Pycurl. dns_cache_timeout,30) # set the time to save the DNS information in seconds 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 () # Submit Request Except Exception as E: Print ("Connection error:", str (e)) Indexfile.close () C.close () Sys.exit () Dns_time=c.getinfo (c.namelookup_time) # get DNS interest Time Connect_time=c.getinfo (c.connect_time) # Gets the time to establish the connection Pretransfer_time=c.getinfo (c.pretransfer_time) # Gets the time from establishing the connection to preparing the transfer Starttransfer_time=c.getinfo (c.starttransfer_time) # Gets the time from when the connection was established to the start of the transfer Total_time=c.getinfo (c.total_time) # Gets the total time of the transfer Http_code=c.getinfo (c.http_code) # get HTTP status Code Size_downland=c.getinfo (c.size_download) # get download package size Head_size=c.getinfo (c.header_size) # get http header size Speed_downland=c.getinfo (c.speed_download) # get average download speed Print ("HTTP Status code :%s"% (Http_code)) Print ("DNS resolution time :%.2f"% (dns_time)) Print (" Establish connection time :%.2f"% (connect_time)) Print (" ready to transfer time :%.2f:"% (Pretransfer_time)) Print (" Transfer start time :%.2f:"% (Starttransfer_time)) Print (" total transfer end time :%.2f"% (total_time)) Print (" download packet size :%d bytes"% size_downland) Print ("HTTP header size :%d byte"% head_size) Print (" average download speed :%d bytes/s"% speed_downland) Indexfile.close () C.close () |