2012-04-16 84 views
3

我試圖改變使用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

回答

3

這是a bug in Beautiful Soup。我已經提交了一個將在下一個版本中發佈的修復程序。

+0

很高興知道這是即將解決的問題:) – cfedermann 2012-04-16 13:12:38