View Single Post
Old 02-06-2011, 04:16 PM   #1
stgabriel
Junior Member
stgabriel began at the beginning.
 
Posts: 2
Karma: 10
Join Date: Feb 2011
Device: Android Phone
Unhappy Problem with replace with

Hello,

I have a big problem with Beautifull soup's replaceWith not working:

I have something like <span class="ngen_F">xxx</span> and want it to be replaced by <b>xxx</b>

my code:

Code:
    def preprocess_html(self, soup):

        # Change 
        for fett in  soup.findAll(name='span',attrs={'class':'ngen_F'}) :
            if fett:
                tag = Tag(soup, 'b')
                tag.insert(0, fett.contents[0])
                print tag
                fett.replaceWith(tag)

        return soup
print tag works. But replaceWith just replaces with ''
When I do fett.replaceWith('<b>test</b>) this is ok.

What's wrong here?

Stefan
stgabriel is offline   Reply With Quote