设置标题标签的字符串属性清除另一个标签的字符串属性在BeautifulSoup

问题描述:

我试图改变使用BeautifulSoup用下面的代码一些HTML文件的标题标签:设置标题标签的字符串属性清除另一个标签的字符串属性在BeautifulSoup

>>> doc = BeautifulSoup(open(filename)) 
>>> root = doc.find('html') # works only with html parser 
>>> hafta = root.find(id="hafta") 
>>> content = hafta.find('div', {'class':'convHtml'}) 
>>> content.find('b').string 
u'BAKANLARA N\u0130\xc7\u0130N KURBAN KES\u0130L\u0130R?' 
>>> doc.title.string = content.find('b').string 
>>> content.find('b').string 
>>> 

奇怪的是,声明doc.title.string = content.find('b').string清除内部content.find('b')字符串。为什么会发生?

+0

你可以发布'filename'引用的HTML源文件吗? – cfedermann 2012-04-16 11:51:37

这是a bug in Beautiful Soup。我已经提交了一个将在下一个版本中发布的修复程序。

+0

很高兴知道这是即将解决的问题:) – cfedermann 2012-04-16 13:12:38