#encoding: Utf-8import urllibimport urllib.request# data is a dictionary and then through Urllib.parse.urlencode () Convert data to ' wd = 904727147 ' string # Finally and URL merge to Full_url# urllib.request is a library, subordinate to Urllib, Urllib is an extensible library of open URLs that collects a lot of URL-handling packages. The # urllib.request template defines a number of function functions and classes that help to open the urls# requests package in the form of a document that is considered to be a higher level HTTP client interface # Urllib.request defines the following function functions: # urllib.reuqest.urlopen (Url,data=none,[timeout,]*,cafile = none, Cadefault = false,context = none) # opens the URL, which can be a string or a Request object. The parameter data must be a byte object, #发送给服务器的附加数据, if no additional data is required, this parameter can also be empty. This data can also be an iterative object, #内容长度值必须在头文件中指定. The current HTTP request is the only data that needs to be used. When the data parameter is provided, the HTTP request will be a post instead of a Get type request. # for HTTP and HTTPS addresses, this function returns a http.client.httpresponse object, #这个对象有 HTTPResponse Objects method # httpresponse.read ([AMT]) reads and returns the response body, or data={}data[' wd '] = ' 904727147 ' url_values = to the next Amt Byte urllib.parse.urlencode (data) url = "http://www.baidu.com/s?" Full_url = url + url_vAluesdata = urllib.request.urlopen (Full_url). Read () data = data.decode (' UTF-8 ') print (data)
Zhongzhiyuan Nanjing 904727147, Jiangsu
Python crawler Basics (i)--Simple URL request