`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' codec can't encode characters in position....
所以当我试图对soup变量进行编码时
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' object has no attribute called 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")
但同样的错误也发生了
那我该怎么编码呢?在
问题是什么?
find_all
不应该抛出编码错误,也不应该对bs4.BeautifulSoup
对象调用encode
,因为encode
返回的是bytestring,而不是soup!-所以你不能对它调用find_all
。在您在任何地方使用
soup.prettify()
吗?在这种情况下,这可能是抛出错误的行。请包含代码的Minimal, Complete and Verifiable example。在相关问题 更多 >
编程相关推荐