gpt4 book ai didi

python - 奇怪的网站编码。是否有可能使用 python 获取它?

转载 作者:可可西里 更新时间:2023-11-01 14:56:08 25 4
gpt4 key购买 nike

例如,我有这句话

Olá mundo!

我需要它写成

ol%E1%20mundo!

创建我的网址。

我需要这个来连接到一些使用这种编码的特定站点。

使用此类编码的站点示例是 Michaellis翻译。

如何使用 python 使用这些类型的编码创建 url?我尝试使用 urllib 和 urllib2,但直到现在我还没有成功。

这里是 another question我的,与此有关。

感谢您的帮助,谢谢。

最佳答案

这是使用 urllibquotestringencode("utf8") 的一种方法:

In  [1]: url = u'Ol\xe1 mundo!'

In [2]: url.encode("utf8")
Out [2]: 'Ol\xc3\xa1 mundo!'

In [3]: print url.encode("utf8")
Olá mundo!

In [4]: urllib.quote(url.encode("utf8"))
Out [4]: 'Ol%C3%A1%20mundo%21'

In [5]: print urllib.quote(url.encode("utf8"))
Ol%C3%A1%20mundo%21

In  [6]: urllib.unquote(urllib.quote(url.encode("utf8")))
Out [6]: 'Ol\xc3\xa1 mundo!'

In [7]: print urllib.unquote(urllib.quote(url.encode("utf8")))
Olá mundo!

关于python - 奇怪的网站编码。是否有可能使用 python 获取它?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8205674/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com