Detailed introduction to using curl library pycurl examples and parameters

高洛峰
Release: 2018-05-11 16:06:03
Original
8761 people have browsed it

pycurl is a powerfulpythonurl library, written inc language. It is very fast, faster than urllib and httplib.

Today we look at the usage and parameters of pycurl in detail

Commonly used methods:

pycurl.Curl() #Method to create a pycurlobject

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 redirects

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

pycurl.Curl().setopt(pycurl.TIMEOUT, 300) #Connection timeout setting

pycurl.Curl().setopt(pycurl.USERAGENT, "Mozilla/5.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 1.1.4322)") #Simulated browsing Device

pycurl.Curl().perform() #Information returned by the server

pycurl.Curl().getinfo(pycurl.HTTP_CODE) #View HTTPstatusSimilar to the status attribute in urllib

pycurl.NAMELOOKUP_TIME domain name resolution time

pycurl.CONNECT_TIME remote server connection time

pycurl.PRETRANSFER_TIME time after connection to start of transmission

pycurl.STARTTRANSFER_TIME The time to receive the first byte

pycurl.TOTAL_TIME The total time of the previous request

pycurl.REDIRECT_TIME If there is a redirection, the time it takes

pycurl.EFFECTIVE_URL

pycurl.HTTP_CODE HTTP response code

pycurl.REDIRECT_COUNTNumber of redirects

pycurl.SIZE_UPLOADData size of upload

pycurl.SIZE_DOWNLOAD Size of downloaded data

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

pycurl.INFO_FILETIME file time information

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

Example:

import StringIO import 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)
Copy after login

Friends who are familiar with PHP may have discovered that the usage of this curl library is very similar to PHP's curl.

The above is the detailed content of Detailed introduction to using curl library pycurl examples and parameters. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!