Python 百分比仅对 URL 中的某些字符进行编码
Python percent encoding only certain characters in a URL
如果 #
字符出现在给定的 url 中,我必须对其进行百分比编码。我知道我们可以使用 urllib.quote
编码 URL。它需要一个 safe
关键字来为 URL 设置一个安全的特定字符。我正在寻找类似的东西:
a = 'http://localhost:8001/3.0/lists/list_1.localhost.org/roster/owner#iammdkdkf'
b = urllib.quote(a,unsafe='#')
此致。
a.replace('#','%23')
怎么样?
如果 #
字符出现在给定的 url 中,我必须对其进行百分比编码。我知道我们可以使用 urllib.quote
编码 URL。它需要一个 safe
关键字来为 URL 设置一个安全的特定字符。我正在寻找类似的东西:
a = 'http://localhost:8001/3.0/lists/list_1.localhost.org/roster/owner#iammdkdkf'
b = urllib.quote(a,unsafe='#')
此致。
a.replace('#','%23')
怎么样?