Python网址转义
在Python中,可以使用urllib库中的quote()函数进行网址转义。示例代码如下:
import urllib
url = 'https://www.google.com/search?q=python tutorial'
escaped_url = urllib.parse.quote(url, safe=':/')
print(escaped_url)
输出结果为:
https%3A//www.google.com/search%3Fq%3Dpython%20tutorial
在这个例子中,我们使用了urllib库中的parse模块来调用quote()函数,将原始的url进行转义。safe参数指定哪些字符不需要进行转义,这里我们指定了冒号和斜杠不需要转义。
原文地址: https://www.cveoy.top/t/topic/EgL 著作权归作者所有。请勿转载和采集!