【发布时间】:2016-07-04 10:05:49
【问题描述】:
`self.urlOpen=urllib.request.urlopen("http://facebook.com")
self.content=self.urlOpen.read()
soup=BeautifulSoup(self.content,"html5lib")
self.links=soup.find_all("a")`
'charmap' 编解码器无法在位置编码字符......
所以当我尝试对汤变量进行编码时
self.urlOpen=urllib.request.urlopen("http://facebook.com")
self.content=self.urlOpen.read()
soup=BeautifulSoup(self.content,"html5lib")
soup=soup.encode("utf-8")
self.links=soup.find_all("a")
'bytes' 对象没有名为 find_all 的属性
我试过了
self.urlOpen=urllib.request.urlopen("http://facebook.com")
self.content=self.urlOpen.read()
soup=BeautifulSoup(self.content.decode("utf-8","ignore"),"html5lib")
self.links=soup.find_all("a")
但同样的错误发生
那我应该怎么编码呢?
【问题讨论】:
-
在寻求调试帮助时包括完整的回溯。
-
还有,
soup.encode('utf-8')只是creates a byte-string出了HTML,当然没有方法find_all()。 -
您可能正在遭受this的困扰:您的终端无法处理输出,而不是beautifulsoup等问题。
-
谢谢@llja Everila.that was breif.but我应该如何编码以防止此类错误?
-
我正在使用
Python 3.4.0 (v3.4.0:04f714765c13, Mar 16 2014, 19:25:23) [MSC v.1600 64 bit (AMD64)] on win32
标签: python encoding utf-8 beautifulsoup