1. Urlopen () method
Urllib.request.urlopen (Url[,data[,proxies])
Create a class file object that represents a remote URL, and then manipulate the class file object like a local file to get remote data
The parameter URL represents the path to the remote data, usually the URL
The parameter data represents a post-submission to a URL (the person who played the web should only have two ways of submitting the data: Post and get. If you are not clear, do not care, because this parameter is rarely used in general)
The parameter proxies is used to set the proxy.
Urlopen () Returns a class file object that provides the following methods:
Read (), ReadLine (), ReadLines (), Fileno (), Close (): These methods are used in exactly the same way as file objects.
info (): Returns a httplib. Httpmessage object that represents the header information returned by the remote server
GetCode (): Returns the HTTP status code, if it is an HTTP request, 200 means the request is successful, 404 means the URL is not found
Geturl (): Returns the requested URL
2. Urlretrieve method
Download remote data directly to a local
Urllib.request.urlretrieve (Url[,filename[,reporthook[,data]])
Parameter description
URL: external or local URL
FileName: The path to the local is established, (if this parameter is not specified, Urllib generates a temporary file to hold the data)
Reporthook: is a callback function that triggers the callback function when the server is connected and the data module of the response is transmitted, and we can use this callback function to display the current download progress
Data: Refers to a post to the server. The method returns a Ganso (filename,headers) filename containing two elements that represents the path saved to the local, headers represents the server response header.
Urlopen () &urlretrieve ()