Tag:python crawler url
#encoding: Utf-8import urllibimport urllib.request# data is a dictionary and then converts data to ' WD = ' via Urllib.parse.urlencode () 904727147 ' string # Finally and URL merge to full_url# urllib.request is a library, the subordinate Urllib,urllib is a collection of a lot of processing URL of the package, open URL of the extensible library. # urllib.request templates Define a number of function functions and classes that help to open a document as a urls# requests package is recognized as a higher-level HTTP Client Interface # Urllib.request defines functions such as the following: # urllib.reuqest.urlopen (url,data=none,[timeout,]*,cafile = None,cadefault = False,context = None) # Open URLs, It 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 to the next Amt Byte data={}data[' wd '] = ' 904727147 ' url_values = 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
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
Python crawler Basics (i)--Simple URL request