table of Contents:
First, an example of crawling pictures
Second, the example of the proper way dictionary translation text
First, an example of crawling pictures
# Introduced dependence Import the urllib.request # string into a request object the Request REQ = urllib.request.Request ( " http://placekitten.com/200/300 " ) # access request objects Request, and returns a response object response = response the urllib.request.urlopen (REQ) # response = the urllib.request.urlopen ( "http://placekitten.com/200/300") is equivalent to the first two steps, urlopen conversion function automatically # Read response object method use Print ( " the read method: pictures will be downloaded to the same directory of the file " ) # read out the response object response, and stored in binary form in a string cat_ing cat_ing = response.read () # binary way cat_ing write cat_ing.jpg files (pictures also file) Open with ( " cat_200_300.jpg " , " WB " ) AS F: f.write (cat_ing) # getURL response object using the method Print ( " getURL Method: " ) cat_url = response.geturl () # returns the link request address URL Print (cat_url) # print it out # info object using the method of the response Print ( " info method: " ) cat_message = response.info () # returns HTTPMessage object. The remote server returned represents the header information of print(cat_message) # print it out # getCode response method using object Print ( " getCode Method: " ) cat_code = response.getcode () # Returns Http status code. If http requests, 200 requests completed successfully; 404 URL Not Found Print (cat_code) # print it out
After running will enter the following:
Second, the example of the proper way dictionary translation text
Reference in this blog:
Zero-based learning portal Python https://www.bilibili.com/video/av4050443?p=55
Python3 in rulopen () Detailed https://blog.csdn.net/qq_41856814/article/details/99658108