python - 如何在python中为url参数编码字符串

标签 python urlencode

这个问题在这里已经有了答案:





How to urlencode a querystring in Python?

(13 个回答)


7年前关闭。




如何对字符串进行编码,以便可以在 url 参数中传递编码后的字符串?

最佳答案

使用 urllib.quote_plus 函数。下面是一个例子:

#!/usr/bin/python

print "Content-Type: text/html;charset=utf-8";
print

import urllib

str = "Hello World?"
str = urllib.quote_plus(str)

print str

输出:
你好+世界%3F

关于python - 如何在python中为url参数编码字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20901768/

相关文章:

python - 使用新的初始迁移来压缩迁移

Python/Pygame字符快速闪烁

python - 在 Keras 中制作自定义规范化层(每个功能)

ios - Swift - 编码 URL

php - 转换为 md5 在 php 中是错误的

forms - 表单数据是否由浏览器自动编码?

python - jupyter笔记本没有运行

python - 查询字符串传递错误

url - 如何在 Emacs Lisp 中 "URL decode"字符串?

Python urlparse.parse_qs unicode url