I try to change title tags of some html documents using BeautifulSoup with the following code:
>>> 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
>>>
Oddly, the statement doc.title.string = content.find('b').string clears the string inside content.find('b'). Why does this occur?
This is a bug in Beautiful Soup. I’ve committed a fix which will be released in the next version.