possible bug of replaceWith?

15 views
Skip to first unread message

Yu Lei

unread,
Dec 3, 2009, 7:49:53 AM12/3/09
to beautifulsoup
Hi, there,

Consider the following code and output:

soup = BeautifulSoup("<b>Argh!</b>")
soup.find(text='Argh!').replaceWith('Hooray!')
soup.b
# <b>Hooray!</b>
soup.b.string
# u'Argh!'

Text 'Argh!' is replaced with 'Hooray!' successfully, just as 'soup.b'
outputs, but 'soup.b.string' still outputs the old value 'Argh!', is
this a bug or something I was missing?

Aaron DeVore

unread,
Dec 3, 2009, 5:31:15 PM12/3/09
to beauti...@googlegroups.com
That is indeed a bug in all versions before the just released
Beautiful Soup 3.0.8. Before that, Tag.string wasn't updated when the
tree was manipulated. Beautiful Soup 3.0.8 calculates Tag.string when
it is accessed using a property, so that bug is entirely fixed.

3.0.8 is available on the Beautiful Soup home page, but hasn't yet
been added to any distro packages. There hasn't been a 3.1.x release
based on the 3.0.8 changes, so that bug is still in 3.1.x.

-Aaron DeVore
> --
>
> You received this message because you are subscribed to the Google Groups "beautifulsoup" group.
> To post to this group, send email to beauti...@googlegroups.com.
> To unsubscribe from this group, send email to beautifulsou...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/beautifulsoup?hl=en.
>
>
>

Yu Lei

unread,
Dec 3, 2009, 9:36:04 PM12/3/09
to beautifulsoup
Got it.

Thanks!

-- YuLei
Reply all
Reply to author
Forward
0 new messages