Python crawler Basics (i)--Simple URL request

Source: Internet
Author: User

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

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.