python - Python 标准库是否包含用于操作 URI 的模块?

标签 python url string

我想将一个 URI 传递给构造函数并取回一个对象,我可以在该对象上调用 obj.type、obj.host、obj.port 等。urllib2 模块的“请求”对象接近于我需要的,但还不够。

最佳答案

也许类似于 urlparse module

The urlparse module is renamed to urllib.parse in Python 3.0.

来自文档:

>>> from urlparse import urlparse
>>> o = urlparse('http://www.cwi.nl:80/%7Eguido/Python.html')
>>> o   # doctest: +NORMALIZE_WHITESPACE
    ParseResult(scheme='http', netloc='www.cwi.nl:80', path='/%7Eguido/Python.html',
    params='', query='', fragment='')
>>> o.scheme
'http'
>>> o.port
80
>>> o.geturl()
'http://www.cwi.nl:80/%7Eguido/Python.html'

关于python - Python 标准库是否包含用于操作 URI 的模块?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2219827/

相关文章:

javascript - 停止 Chrome 自动完成 URL 哈希?

c# - 将基本类型(日期、数字)转换为字符串并返回以保存到 C# 中的数据库

python - 使用 call() 执行 cat,在 python 中使用管道和重定向输出

java - 如何替换 URL 字符串中的特定 '&' 进行解析

python - unix vim 处理 BufRead 自动命令时检测到错误

swift - url.appendPathComponent 产生错误不能在不可变值 : function call returns 上使用变异成员

string - 使用 awk 或 send 查找字符串并在其前面插入另一个复杂字符串

string - 在 Elixir 中将二进制字符串转换为十六进制,反之亦然

python - 在模板中指定 Django CMS 占位符类型(文本、图片、链接)

python - 即使在 pretty_print=True 时,使用 lxml 编写也不会发出空格