Pycurl Module
#!/usr/bin/env python
#-*-Coding:utf-8-*-
Import Os,sys
Import time
Import Sys
Import Pycurl
Url= "Http://www.yitongjia.com"
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,e:
Print "Connecion 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 (pycurl. 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 Status code:%s"% (Http_code)
Print "DNS resolution time:%.2f MS"% (namelookup_time*1000)
Print "Establish connection time:%.2f ms"% (connect_time*1000)
Print "Ready to transfer time:%.2f MS"% (pretransfer_time*1000)
Print "Transfer start time:%.2f ms"% (starttransfer_time*1000)
Print "Total transfer end time:%.2f MS"% (total_time*1000)
print "Download packet size:%d bytes/s"% (size_download)
Print "HTTP header size:%d byte"% (Speed_download)
print "Average download speed:%d bytes/s"% (speed_download)
Indexfile.close ()
C.close ()
This article is from the "Eight Miles" blog, so be sure to keep this source http://5921271.blog.51cto.com/5911271/1583201
Python pycurl module operation and maintenance automation