Use the curl Library pycurl instance and parameter details

Source: Internet
Author: User
Pycurl is a powerful python url library written in C language and is faster than urllib and httplib. Today, let's take a look at the usage of pycurl and common methods of parameter explanation: p pycurl is a powerful python url library written in C language and is faster than urllib and httplib.

Today, let's take a look at the usage and parameter details of pycurl.

Common methods:

Pycurl. Curl () # method for creating a pycurl object

Pycurl. Curl (). setopt (pycurl. URL, http://www.pythontab.com) # set the URL to be accessed

Pycurl. Curl (). setopt (pycurl. MAXREDIRS, 5) # set the maximum number of redirection times

Pycurl. Curl (). setopt (pycurl. CONNECTTIMEOUT, 60)

Pycurl. Curl (). setopt (pycurl. TIMEOUT, 300) # connection TIMEOUT settings

Pycurl. Curl (). setopt (pycurl. USERAGENT, "Mozilla/5.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) # view the HTTP status similar to the status attribute in urllib

Pycurl. NAMELOOKUP_TIME domain name resolution time

Pycurl. CONNECT_TIME remote server connection time

Pycurl. PRETRANSFER_TIME: the time from the connection to the start of transmission

Time when pycurl. STARTTRANSFER_TIME receives the first byte

Total time of the request on pycurl. TOTAL_TIME

Pycurl. REDIRECT_TIME if there is a redirection, the time spent

Pycurl. inclutive_url

Pycurl. HTTP_CODE HTTP response code

Pycurl. REDIRECT_COUNT redirect times

Data size uploaded by pycurl. SIZE_UPLOAD

Pycurl. SIZE_DOWNLOAD data size

Pycurl. SPEED_UPLOAD upload speed

Pycurl. HEADER_SIZE header size

Pycurl. REQUEST_SIZE request size

Pycurl. CONTENT_LENGTH_DOWNLOAD download content length

Pycurl. CONTENT_LENGTH_UPLOAD Upload content length

Pycurl. CONTENT_TYPE content type

Pycurl. RESPONSE_CODE response code

Pycurl. SPEED_DOWNLOAD download speed

Pycurl. SSL_VERIFYRESULT

Time information of the pycurl. INFO_FILETIME file

Pycurl. HTTP_CONNECTCODE HTTP connection code

Pycurl. HTTPAUTH_AVAIL

Pycurl. PROXYAUTH_AVAIL

Pycurl. OS _ERRNO

Pycurl. NUM_CONNECTS

Pycurl. SSL_ENGINES

Pycurl. INFO_COOKIELIST

Pycurl. LASTSOCKET

Pycurl. FTP_ENTRY_PATH


Instance:

import StringIOimport pycurl c = pycurl.Curl()str = StringIO.StringIO()c.setopt(pycurl.URL, "http://www.pythontab.com")c.setopt(pycurl.WRITEFUNCTION, str.write)c.setopt(pycurl.FOLLOWLOCATION, 1) c.perform()print c.getinfo(pycurl.EFFECTIVE_URL)

A friend familiar with php may have discovered that the curl library is very similar to php curl.

The above is the details about using the curl Library pycurl instance and parameters. For more information, see other related articles in the first PHP community!

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.