Python pycurl and pythonpycurl

Source: Internet
Author: User

Python pycurl and pythonpycurl

Common Methods:

pycurl.Curl()  # Method for creating a pycurl object pycurl.Curl(pycurl.URL, http: //www .google.com.hk)  # Set the URL to be accessed pycurl.Curl().setopt(pycurl.MAXREDIRS, 5)  # Set the maximum number of redirection timesPycurl. Curl (). setopt (pycurl. CONNECTTIMEOUT, 60) pycurl.Curl().setopt(pycurl.TIMEOUT, 300)  # Connection timeout settings pycurl.Curl().setopt(pycurl.USERAGENT,  "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 1.1.4322)" # Simulate a browser pycurl.Curl().perform()  # Information returned by the server pycurl.Curl().getinfo(pycurl.HTTP_CODE)  # Viewing the HTTP status is similar to the status attribute in urllibPycurl. NAMELOOKUP_TIME domain name resolution time pycurl. CONNECT_TIME remote server connection time pycurl. the time from PRETRANSFER_TIME connection to start transmission pycurl. STARTTRANSFER_TIME receives the time of the first byte pycurl. total time of the request on TOTAL_TIME pycurl. REDIRECT_TIME if there is a redirection, it takes time to pycurl. EFFECTIVE_URLpycurl.HTTP_CODE HTTP response code pycurl. REDIRECT_COUNT redirect times pycurl. the size of the data uploaded by SIZE_UPLOAD is pycurl. SIZE_DOWNLOAD the data size pycurl. SPEED_UPLOAD upload speed: pycurl. HEADER_SIZE header size pycurl. request size: pycurl. CONTENT_LENGTH_DOWNLOAD download content length: pycurl. CONTENT_LENGTH_UPLOAD the length of the uploaded content pycurl. the CONTENT_TYPE content type pycurl. RESPONSE_CODE response code pycurl. SPEED_DOWNLOAD download speed: pycurl. the time information of the SSL_VERIFYRESULTpycurl.INFO_FILETIME file pycurl. HTTP_CONNECTCODE HTTP connection code pycurl. example: Get the real URL of a Weibo short URL
 1 import StringIO 2 import pycurl 3   4 c = pycurl.Curl() 5 str = StringIO.StringIO() 6 c.setopt(pycurl.URL, "http://t.cn/RLlwzRh") 7 c.setopt(pycurl.WRITEFUNCTION, str.write) 8 c.setopt(pycurl.FOLLOWLOCATION, 1) 9  10 c.perform()11 print c.getinfo(pycurl.EFFECTIVE_URL)

 

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.