HTTP The agreement is very important , without HTTP It can be said that there is no Internet . Because browsing all the pages , All from HTTP Protocol support , Not just news sites , It also includes shopping websites , There are also many search sites . stay Python in http.client Modules provide some classes , Can be directed to HTTP The server sends the request , And read the server's response .
First make sure the server's URL Connect , Then create HTTPConnection Object and initiate a connection to the server , And then call request Send request to server , Last call getresponse Get the return object . By returning an object , You can read the content of the message that the server responds to .
The source code of the whole example is as follows ：
# Learning algorithm notes - Cai Junsheng （qq:9073204) #https://mysoft.blog.csdn.net/ #2020-10-27 import http.client as h HOST = "www.sznews.com" fileName = 'test_cai.jpg' # establish HTTPConnection object conn = h.H