Detailed introduction to network programming

零下一度
Release: 2017-07-24 17:26:09
Original
1607 people have browsed it

Python has built-in libraries that encapsulate many common network protocols, so python has become a powerful network programming tool. Here is a brief description of python's network programming.

urllib and urllib2 modules

urllib and urllib2 are the most powerful network working libraries in the Python standard library. Here is a brief introduction to the urllib module. This time we mainly use several commonly used modules in the urllib module:

urlopen
parse
urlencode
quote
unquote
_safe_quoters
unquote_plus
Copy after login

GET request:

Use urllib to make a get request of the http protocol and obtain Return value of the interface:

 urllib.request = res =(res.decode())
Copy after login

POST request:

 urllib.request  urllib.parse = data =: : : param =res ==(type(res_str), res_str)
Copy after login

Note: When using urllib to request the post interface, in the above example, post The request parameter type of the interface is in key-value format, and parameters in json format are not applicable.

Quote module

Escapes special characters when the requested URL contains special characters.

 urllib.parse = new_url =(new_url)
Copy after login

Unquote module

Performs parsing operations on escaped special characters.

 urllib.parse = new_url =(, unquote_plus(url4))
Copy after login

The above is a brief introduction to urllib. When processing the interface, please also refer to the requests module~~~

<br>
Copy after login

The above is the detailed content of Detailed introduction to network programming. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!