Python crawler Basics (i)--Simple URL request

Source: Internet
Author: User

#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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.