Python 为什么我会得到这个(显然)不寻常的属性错误:';字节';对象没有属性'_所有字符串';?有办法绕过它吗?
我一直在寻找一个解决这个属性错误的方法,但我一直找不到解决“所有字符串”的方法 我想编写一个网络爬虫,但是在页面的顶部和底部有很多无意义的东西,所以我尝试清理HTML代码,作为排除网页顶部和底部不必要噪音的前提 当我运行下面的代码,特别是最后一行代码时,我得到一个AttributeError:Python 为什么我会得到这个(显然)不寻常的属性错误:';字节';对象没有属性'_所有字符串';?有办法绕过它吗?,python,html,beautifulsoup,web-crawler,attributeerror,Python,Html,Beautifulsoup,Web Crawler,Attributeerror,我一直在寻找一个解决这个属性错误的方法,但我一直找不到解决“所有字符串”的方法 我想编写一个网络爬虫,但是在页面的顶部和底部有很多无意义的东西,所以我尝试清理HTML代码,作为排除网页顶部和底部不必要噪音的前提 当我运行下面的代码,特别是最后一行代码时,我得到一个AttributeError: from __future__ import division from urllib.request import urlopen from bs4 import BeautifulSoup text
from __future__ import division
from urllib.request import urlopen
from bs4 import BeautifulSoup
textSource = 'http://celt.ucc.ie/irlpage.html'
html = urlopen(textSource).read()
raw = BeautifulSoup.get_text(html)
这是我得到的完整回溯:
Traceback (most recent call last):
File "...Crawler_Celt_Namelink_Test.py", line 7, in <module>
raw = BeautifulSoup.get_text(html)
File "...Python\Python35\lib\site-packages\bs4\element.py", line 950, in get_text
return separator.join([s for s in self._all_strings(
AttributeError: 'bytes' object has no attribute '_all_strings'
回溯(最近一次呼叫最后一次):
文件“…Crawler\u Celt\u Namelink\u Test.py”,第7行,在
raw=BeautifulSoup.get_文本(html)
get_文本中的文件“…Python\Python35\lib\site packages\bs4\element.py”第950行
返回分隔符。连接([s代表self.\u所有字符串中的s(
AttributeError:“bytes”对象没有属性“\u所有\u字符串”
以前有人遇到过这个错误吗?或者有人能建议我如何克服它吗?当你看到它是这样使用的:
from urllib.request import urlopen
from bs4 import BeautifulSoup
textSource = 'http://celt.ucc.ie/irlpage.html'
html = urlopen(textSource).read()
soup = BeautifulSoup(html, 'html.parser')
raw = BeautifulSoup.get_text(soup)