BeautifulSoup cannot concatenate str and NoneType objects
hi im running python 2.7.1 and beautifulsoup 3.2.0 if i try to load some xml feed using
ifile = open(os.path.join(self.path,str(self.FEED_ID)+'.xml'), 'r')
file_data = BeautifulStoneSoup(ifile,
convertEntities=BeautifulStoneSoup.XHTML_ENTITIES)
im getting the following error
File "C:\dev\Python27\lib\site-packages\BeautifulSoup.py", line 1144, in __ini
t__
self._feed(isHTML=开发者_StackOverflow中文版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
i try to look everywhere but with no success ... please advise
With the example ...
from BeautifulSoup import BeautifulStoneSoup
xml = "<doc><tag1>Contents 1<tag2>Contents 2<tag1>Contents 3"
soup = BeautifulStoneSoup(xml)
print soup.prettify()
(...)
from here. I infer that you need to pass a string as first parameter instead of the file object ifile
, try:
file_data = BeautifulStoneSoup(ifile.read(),
convertEntities=BeautifulStoneSoup.XHTML_ENTITIES)
I had this error too. This worked for me:
from unidecode import unidecode
file_data = BeautifulSoup(unidecode(ifile.read()))
精彩评论