您可以使用urllib.parse.quote()对URL的路径部分进行编码。
#!/usr/bin/env python3from urllib.parse import quotefrom urllib.request import urlopenurl = 'http://zh.wikipedia.org/wiki/' + quote("毛泽东")content = urlopen(url).read()
您可以使用urllib.parse.quote()对URL的路径部分进行编码。
#!/usr/bin/env python3from urllib.parse import quotefrom urllib.request import urlopenurl = 'http://zh.wikipedia.org/wiki/' + quote("毛泽东")content = urlopen(url).read()