我尝试使用BeautifulSoup和urllib获取一些Google结果:
from urllib.request import Request, urlopen
from urllib.parse import quote
from bs4 import BeautifulSoup
url = "http://www.google.de/search?q=" + quote("ätzend")
req = Request(url, headers={'User-Agent': 'Mozilla/5.0'})
soup = BeautifulSoup(urlopen(req),"html.parser")
for item in soup.select(".r a"):
print(item.text)
这是结果:
�tzende Stoffe � Wikipedia
�tzende Stoffe � Wikipedia
�tzend � Wikipedia
我尝试使用decode('utf-8')
并没有帮助。我该怎么办?
编辑: 还尝试过:
soup = BeautifulSoup(urlopen(req).read().decode('utf-8'),"html.parser")
同样的问题。使用utf-16也无济于事。字母“Ä”的Unicode为196 => C4。
Edit2: Windows Power Shell显示正确的结果。