urllib 下载时遇见链接中含有中文
2018-08-16 本文已影响0人
北游_
import urllib.parse
url = 'http://example.com/unicodè'
url = urllib.parse.urlsplit(url)
url = list(url)
url[2] = urllib.parse.quote(url[2])
url = urllib.parse.urlunsplit(url)
print(url)
参考链接:
https://stackoverflow.com/questions/4389572/how-to-fetch-a-non-ascii-url-with-python-urlopen