gpt4 book ai didi

python - BeautifulSoup 无法连接 str 和 NoneType 对象

转载 作者:太空宇宙 更新时间:2023-11-03 12:10:02 27 4
gpt4 key购买 nike

嗨,我正在运行 python 2.7.1 和 beautifulsoup 3.2.0如果我尝试使用

加载一些 xml 提要
ifile = open(os.path.join(self.path,str(self.FEED_ID)+'.xml'), 'r')
file_data = BeautifulStoneSoup(ifile,
convertEntities=BeautifulStoneSoup.XHTML_ENTITIES)

我收到以下错误

  File "C:\dev\Python27\lib\site-packages\BeautifulSoup.py", line 1144, in __ini
t__
self._feed(isHTML=isHTML)
File "C:\dev\Python27\lib\site-packages\BeautifulSoup.py", line 1186, in _feed

SGMLParser.feed(self, markup)
File "C:\dev\Python27\lib\sgmllib.py", line 103, in feed
self.rawdata = self.rawdata + data
TypeError: cannot concatenate 'str' and 'NoneType' objects

我试着到处寻找,但没有成功......请指教

最佳答案

以例子...

from BeautifulSoup import BeautifulStoneSoup
xml = "<doc><tag1>Contents 1<tag2>Contents 2<tag1>Contents 3"
soup = BeautifulStoneSoup(xml)
print soup.prettify()
(...)

来自 here .我推断你需要传递一个字符串作为第一个参数而不是文件对象ifile,试试:

file_data = BeautifulStoneSoup(ifile.read(), 
convertEntities=BeautifulStoneSoup.XHTML_ENTITIES)

关于python - BeautifulSoup 无法连接 str 和 NoneType 对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6110578/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com