python3.4中urllib 有没有urlencode函数

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了python3.4中urllib 有没有urlencode函数相关的知识,希望对你有一定的参考价值。

    有,python 3.x中urllib和urilib2合并成了urllib。

    其中urllib2.urlopen()变成了urllib.request.urlopen()

    urllib2.Request()变成了urllib.request.Request()

    Python是一种面向对象、直译式计算机程序设计语言,由荷兰人Guido van Rossum发明于1989年,1991年发行第一个公开发行版。它常被昵称为胶水语言,它能够很轻松的把用其他语言制作的各种模块轻松地联结在一起。

    Python是纯粹的自由软件, 源代码和解释器CPython遵循 GPL协议。语法简洁清晰,特色之一是强制用空白符作为语句缩进。

    Python是一种解释型、面向对象、动态数据类型的高级程序设计语言。自从20世纪90年代初Python语言诞生至今,它逐渐被广泛应用于处理系统管理任务和Web编程。Python已经成为最受欢迎的程序设计语言之一。

    由于Python语言的简洁、易读以及可扩展性,在国外用Python做科学计算的研究机构日益增多,一些知名大学已经采用Python教授程序设计课程。例如麻省理工学院的计算机科学及编程导论课程就使用Python语言讲授。

    众多开源的科学计算软件包都提供了Python的调用接口,例如著名的计算机视觉库OpenCV、三维可视化库VTK、医学图像处理库ITK。

参考技术A python3.x中urlencode在urllib.parse模块中
使用方式urllib.parse.urlencode
urllib.parse.urlencode(query,
doseq=False, safe='', encoding=None,
errors=None, quote_via=quote_plus)

Convert a mapping object or a sequence of two-element tuples, which may
contain str
or bytes objects, to a “percent-encoded” string. If the
resultant string is to be used as a data for POST operation with urlopen() function, then it should be properly
encoded to bytes, otherwise it would result in a TypeError.

The resulting string is a series of key=value pairs separated by '&' characters, where
both key and value are quoted using the quote_via
function. By default, quote_plus() is used to quote the values, which
means spaces are quoted as a '+' character and ‘/’ characters are encoded as %2F, which follows the
standard for GET requests (application/x-www-form-urlencoded). An alternate
function that can be passed as quote_via is quote(), which will encode spaces as %20 and not encode ‘/’
characters. For maximum control of what is quoted, use quote and specify a value
for safe.

When a sequence of two-element tuples is used as the query argument,
the first element of each tuple is a key and the second is a value. The value
element in itself can be a sequence and in that case, if the optional parameter
doseq is evaluates to True, individual key=value pairs separated
by '&' are
generated for each element of the value sequence for the key. The order of
parameters in the encoded string will match the order of parameter tuples in the
sequence.

The safe, encoding, and errors parameters are
passed down to quote_via (the encoding and errors
parameters are only passed when a query element is a str).

To reverse this encoding process, parse_qs() and parse_qsl() are provided in this module to parse
query strings into Python data structures.

Refer to urllib examples to
find out how urlencode method can be used for generating query string for a URL
or data for POST.

Changed in version 3.2: Query parameter
supports bytes and string objects.

以上是关于python3.4中urllib 有没有urlencode函数的主要内容,如果未能解决你的问题,请参考以下文章

python3 urllib用法

python3.4 + requests + re 仿写糗事百科爬虫,遇到一个疑惑,求助

Python中urlopen()介绍

什么是全局默认超时

httpliburlliburllib2的区别

城市经纬度(阿里云)