我尝试用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。你知道吗
编辑2: Windows Power Shell显示正确的结果。你知道吗
目前没有回答
相关问题 更多 >
编程相关推荐