python3.4没有 urllib2

Posted

tags:

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

再也不能更新的初学者。。
我用的是python3.4,我的python里并没有urllib2这个库啊,只有urllib。我看网上有讲urllib把urllib2和urllib给合到一起了?是这样么?我从github上下载了一个程序,人家用到了urllib2这个库,然后我用的是eclipse+pydev,上面全是报错。我该怎么办。。是要从哪里下载一下urllib2还是我需要把他的程序给改了?谢谢!

看python解释器目录底下,有一个Scripts文件夹

将这个文件夹添加至环境变量或者在命令行cd到这个目录下,有俩种办法可以获取第三方包

    pip install urllib2

    easy_install urllib2

获取之后重启ide

参考技术A python 3.x中urllib库和urilib2库合并成了urllib库。。
其中urllib2.urlopen()变成了urllib.request.urlopen()
urllib2.Request()变成了urllib.request.Request()
……本回答被提问者和网友采纳
参考技术B py3版本之后urllib模块合并为urllib.request了。

原先的一些函数方法变化不大,只是多加了一个request而已。比如urllib.request.urlopen()

参考:http://www.cnblogs.com/Lands-ljk/p/5447127.html
参考技术C 是的python3里面把两个库合并了,需要改程序,但是改的可能很复杂,也可能比较简单,具体要看程序。建议找找看有没有python3的版本或者找别的类似程序吧 参考技术D 如果只是import urllib还是不对
需要import urllib.request才能再进行urllib request.urlopen()和urllib.request.Request()

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没有 urllib2的主要内容,如果未能解决你的问题,请参考以下文章

python3.4中urllib 有没有urlencode函数

python有没有类似inet_addr函数

python3.4自带的pip怎样修改默认源

centos6安装python3.4和pip3

centos6安装python3.4和pip3

python3.4中 import pymssql 后,当UPDATE语句执行完成,如何返回执行行数,请给出详细代码