1 httplib IntroductionHttplib is a client implementation of the HTTP protocol in Python that can be used to interact with the HTTP serverHttplib is a relatively low-level HTTP request module, which has a special packaging module, such as Urllib built-in modules, Goto and other third-party modules, but the higher the package is not flexible, such as the Urllib module in the request error will not return the
This article mainly introduces the use of Httplib module to make Python under the HTTP client method, the article listed some httplib under the common HTTP method, the need for friends can refer to the
Httplib is a client-side implementation of the HTTP protocol in Python t
When you use the new version of python to open the old version of the Code, some errors or incompatibility may occur, today, we will analyze one of the cases. Before using httplib in Python 2.7 for interface testing, the running code is normal,
After using Python 3.3 recently, I checked the previous Code and found tha
Before using the Python 2.7 version of Httplib to do interface testing, the running code is normal,
Recently started using Python 3.3, and then look at the previous code, found that import httplib error: Unresolved import:httplib,
Error when running code: Importerror:no module named '
= httpconnection ('www .baidu.com: 80') conn2 = httpconnection ('www .baidu.com ', 80) conn3 = httpconnection ('www .baidu.com', 80, true, 10) error instance: conn3 = httpconnection ('www .baidu.com: 80', true, 10)
Return Value:The httpconnection class will instance and return an httpconnection object
2. Class httplib. httpsconnectionNote:This class is used to create an HTTPS request link
Prototype:Httpsconnection (host [, Port [, key_file [, ce
Python urllib, urllib2, and httplib Capture web page code instances
This article mainly introduces Python urllib, urllib2, and httplib to capture Web Page code instances. This article provides the demo code directly. The Code contains detailed comments. For more information, see
Use urllib2, too powerful
I tried to use
In Python, analog HTTP clients send get and post requests, primarily with the functionality of the Httplib module.1. Python sends a GET requestI built a test environment locally, the test.php content is to output a sentence:
1
echo‘Old friends and old wines are best.‘;
Python sends a GET
Example 1: Use httplib to access a URL and obtain the returned content:
Code highlighting produced by Actipro CodeHighlighter (freeware)http://www.CodeHighlighter.com/-->
Import
HttplibConn
=
Httplib. httpconnection (
"
Www.cnblogs.com
"
)Conn. Request (
"
Get
"
,
"
/Coderzh/archive/2008/05/13/1194445 .html
"
)R
=
Conn. getresponse ()
Print
R. Read ()
#
Get all c
#! /Usr/bin/env python #-*-coding: UTF-8-*-import httplibhttplib. HTTPConnection. debuglevel = 1 ''' 200 normal status code does not jump, and locationconn = httplib. HTTPConnection ("tu.duowan.com") # Here Is hostconn. request ('get', '/m/meinv/index.html ') # The above is the branch Note: GET ''' # You can find locationconn = httplib in headers to access the re
= httpconnection (' www.baidu.com ',)
conn3 = Httpconnection (' www.baidu.com ', 80,true,10)
Error instance:
conn3 = httpconnection (' www.baidu.com:80 ', true,10)
Return:
Httpconnection class will instantiate and return a Httpconnection object
2, Class Httplib. Httpsconnection
Description
This class is used to create a request link of HTTPS type
Prototype:
Httpsconnection (host[, port[, key_file[, cert_file[, strict[, timeout]]]
Key_file: A p
Recently in learning Python, just the boss recently let me do a POST request Test Web Service is normal to enable the small monitoring, the Internet to check the next information, found that the powerful Python can be used, so they are now learning to sell, by the way to exercise their own.Because I also just contact this piece soon belongs to rookie level, so before the task, can only surf the web based on
It's too powerful to use URLLIB2.
Try to use the proxy login to pull the cookie, jump to capture the picture ...
Document: Http://docs.python.org/library/urllib2.html
Directly on the demo code.Includes: direct pull, use of reuqest (Post/get), use of proxies, cookies, jump processing
#!/usr/bin/python#-*-coding:utf-8-*-# urllib2_test.py# author:wklken# 2012-03-17 wklken@yeah.netimport urllib, Urllib2,cookielib,socketurl = "Http://www.testurl ..." #ch
Python httplib module instance, pythonhttplib
The httplib module is an underlying basic module that provides fewer functions and is rarely used under normal circumstances. We recommend using urllib, urllib2, and httplib2.
HTTPConnection object
Class httplib. HTTPConnection (host [, port [, strict [, timeout [, source_
Httplib is a client implementation of the HTTP protocol in Python that can be used to interact with the HTTP server.As in Example 1:Import Httpliburl = "Www.126.com"conn = Httplib. Httpconnection (URL)TryConn.request (' Get ', '/')result = Conn.getresponse () #获取http响应Print Result.read () #返回网页内容 (message body)Print Result.status #返回响应的状态码Print Result.reason #返回服
Httplib module is a low-level basic module, the implementation of a relatively small, under normal circumstances less use. Recommended Urllib, URLLIB2, Httplib2.
Httpconnection objects
Class Httplib. Httpconnection (host[, port[, strict[, timeout[, Source_address]]]
Creating Httpconnection Objects
Httpconnection.request (method, url[, body[, headers])
Send Request
Httpconnection.getresponse ()
Get
This article mainly introduces Python urllib, URLLIB2, httplib Crawl page code example, this article directly gives the demo code, code contains detailed comments, the need for friends can refer to the
Using URLLIB2, it's too powerful.
Try to use the proxy landing pull cookies, jump grab pictures ...
Documents: http://docs.python.org/library/urllib2.html
Directly on the demo code.
Includes: direct pull
In Python, analog HTTP clients send get and post requests, primarily with the functionality of the Httplib module.1. Python sends a GET requestI built a test environment locally, the test.php content is to output a sentence:
1
echo‘Old friends and old wines are best.‘;
Python sends a GET
Comparison between Python 2 and Python 3 and python 3
I. version Comparison
The Python version is mainly divided into two categories:
Python 2.7.3 is the most widely used
Python development [initial]: Install Python 3 and Python 3 in Linux
By default, the Linux system comes with python, Which is depended on by many programs in the system. Therefore, it is recommended that you do not delete it easi
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.