Python pycurl module operation and maintenance automation

Source: Internet
Author: User

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

Related Article

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.