How to deal with unicode string in URL in python3?

You could use urllib.parse.quote() to encode the path section of URL.

#!/usr/bin/env python3
from urllib.parse   import quote
from urllib.request import urlopen

url="http://zh.wikipedia.org/wiki/" + quote("毛泽东")
content = urlopen(url).read()

Leave a Comment