BeautifulGroup无法连接str和NoneType对象

2024-04-27 04:07:14 发布

您现在位置:Python中文网/ 问答频道 /正文

嗨,我正在运行python2.7.1和beautifulsoup3.2.0 如果我试图使用

ifile = open(os.path.join(self.path,str(self.FEED_ID)+'.xml'), 'r')
file_data = BeautifulStoneSoup(ifile, 
    convertEntities=BeautifulStoneSoup.XHTML_ENTITIES)

我得到以下错误

^{pr2}$

我试着到处找,但没有成功。。。请告知


Tags: pathselfiddataosfeedxmlopen
2条回答

我也有这个错误。这对我很有效:

from unidecode import unidecode
file_data = BeautifulSoup(unidecode(ifile.read()))

举个例子。。。在

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

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

^{pr2}$

相关问题 更多 >