1. 程式人生 > >Python3進行URL解碼及編碼

Python3進行URL解碼及編碼

from urllib.parse import unquote,quote

url1 = "https://www.qichacha.com/search?key=河南正商河洛置業有限公司"
url2 = "https://www.qichacha.com/search?key=%E6%B2%B3%E5%8D%97%E6%AD%A3%E5%95%86%E6%B2%B3%E6%B4%9B%E7%BD%AE%E4%B8%9A%E6%9C%89%E9%99%90%E5%85%AC%E5%8F%B8"
# 解碼
url = unquote(url2)
print(url)
#編碼
url = quote("河南正商河洛置業有限公司")
print(url)