|
|
#1 |
|
Junior Member
![]() Posts: 2
Karma: 10
Join Date: Feb 2011
Device: Android Phone
|
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
When I do fett.replaceWith('<b>test</b>) this is ok. What's wrong here? Stefan |
|
|
|
|
|
#2 |
|
Member
![]() 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.
|
|
|
|
![]() |
| Tags |
| replacewith |
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| regex replace??? | schuster | Conversion | 14 | 01-29-2011 10:02 AM |
| How to replace a masthead | weebl | Calibre | 6 | 12-02-2010 10:01 AM |
| Using Find/Replace with BD | Otter | Sony Reader | 7 | 02-28-2009 02:49 PM |
| Replace battery ?? | singring | Fictionwise eBookwise | 1 | 02-11-2008 02:45 PM |
| Replace Handstory | elveejay | Lounge | 3 | 06-04-2005 11:10 PM |