我从freebase dump上得到了一些维基百科网址:
url 1:http://pt.wikipedia.org/wiki/Pedro_Miguel_de_Castro_Brand%25C3%25A3o_Costa
url 2:http://pt.wikipedia.org/wiki/Pedro_Miguel_de_Castro_Brand%E3o_Costa
他们都提到了维基百科上的同一页:
网址3:http://pt.wikipedia.org/wiki/Pedro_Miguel_deu Castro_Brandãu Costa
urllib.unquote
在url 1上工作
url = 'Pedro_Miguel_de_Castro_Brand%25C3%25A3o_Costa'
url = urllib.unquote(url)
url = urllib.unquote(url)
print url
结果是
^{pr2}$但不适用于url 2。在
url = 'Pedro_Miguel_de_Castro_Brand%E3o_Costa'
url = urllib.unquote(url)
print url
结果是
Pedro_Miguel_de_Castro_Brand�o_Costa
有什么不对劲吗?在
前者是双引号UTF-8,因为您的终端使用UTF-8,所以通常打印出来。后者引用拉丁语-1,需要先解码。在
相关问题 更多 >
编程相关推荐