Register Guidelines E-Books Today's Posts Search

Go Back   MobileRead Forums > E-Book Software > Calibre > Recipes

Notices

Reply
 
Thread Tools Search this Thread
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
Old 02-06-2011, 04:37 PM   #2
alison87
Member
alison87 began at the beginning.
 
Posts: 15
Karma: 10
Join Date: Feb 2011
Device: Kindle 3G
I had exactly the same problem yesterday when i was trying to insert a Tag. I don't think it's worth worrying about - might as well just use what works and pass a simple HTML string to insert/replaceWith. Tag objects don't seem to work the way BeautifulSoup's documentation says they do.
alison87 is offline   Reply With Quote
Advert
Reply

Tags
replacewith


Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
regex replace??? schuster Conversion 14 01-29-2011 09:02 AM
How to replace a masthead weebl Calibre 6 12-02-2010 09:01 AM
Using Find/Replace with BD Otter Sony Reader 7 02-28-2009 01:49 PM
Replace battery ?? singring Fictionwise eBookwise 1 02-11-2008 01:45 PM
Replace Handstory elveejay Lounge 3 06-04-2005 10:10 PM


All times are GMT -4. The time now is 08:29 AM.


MobileRead.com is a privately owned, operated and funded community.