脚本之家,脚本语言编程技术及教程分享平台!
分类导航

Python|VBS|Ruby|Lua|perl|VBA|Golang|PowerShell|Erlang|autoit|Dos|bat|

服务器之家 - 脚本之家 - Python - python字符串与url编码的转换实例

python字符串与url编码的转换实例

2021-02-20 00:04Tangzongyu123 Python

今天小编就为大家分享一篇python字符串与url编码的转换实例,具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧

主要应用的场景

爬虫生成带搜索词语的网址

1.字符串转为url编码

?
1
2
3
4
5
6
import urllib
poet_name = "李白"
url_code_name = urllib.quote(poet_name)
print url_code_name
#输出
#%E6%9D%8E%E7%99%BD

2.url编码转为字符串

?
1
2
3
4
5
6
import urllib
url_code_name = "%E6%9D%8E%E7%99%BD"
name = urllib.unquote(url_code_name)
print name
#输出
#李白

以上这篇python字符串与url编码的转换实例就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持服务器之家。

原文链接:https://blog.csdn.net/Tangzongyu123/article/details/75224468

延伸 · 阅读

精彩推荐