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 06-04-2011, 07:49 PM   #1
BRGriff
Connoisseur
BRGriff began at the beginning.
 
Posts: 58
Karma: 12
Join Date: May 2011
Location: Deland, Florida
Device: Kindle 3
Remove "alink", not just change it to text

I found code on this forum written by Starson17 which allows for the changing of an "alink" to a text object. The code works fine and once converted to a text object, I can manipulate it with extra css to diminish the text's size and therefore accomplish part of what I want: to maximize the available screen area for viewing an image.

Starson17's code is:

Code:
    def preprocess_html(self, soup):
        for alink in soup.findAll('a'):
            if alink.string is not None:
               tstr = alink.string
               alink.replaceWith(tstr)
        return soup
My question is this: Once I have found the "alink" tag, as is done by Starson17's code, how can I "remove" it instead of "replacing" it with a string?

Seems to me if I could define the "tstr" as a null item, there would no longer be an "alink". I tried "tstr = []" but that did not work! Any other suggestions?

Any help would be greatly appreciated.
BRGriff is offline   Reply With Quote
Old 06-04-2011, 07:54 PM   #2
kovidgoyal
creator of calibre
kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.
 
kovidgoyal's Avatar
 
Posts: 43,850
Karma: 22666666
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
tag.extract()
kovidgoyal is offline   Reply With Quote
Advert
Old 06-04-2011, 10:35 PM   #3
BRGriff
Connoisseur
BRGriff began at the beginning.
 
Posts: 58
Karma: 12
Join Date: May 2011
Location: Deland, Florida
Device: Kindle 3
IT WORKED!!! Thank you!!!

Kovid,

I was a little frustrated that you were being so cryptic, especially since I am so very new to all of this. But I want to thank you for giving me a hint and letting me learn. I did research on your suggestion to use "tag.extract()". I fumbled around but finally got it! I can not tell you how thrilling it was, even though you could have written the code while half asleep.

Code:
        def preprocess_html(self, soup): 
          for tag in soup.findAll('a'):
            tag.extract() 
          return soup
I hope it will be added to the "Recipes Reusable Code" under Remove "alink" or "inline" html tags. Of course, the posting should be under your name as you are the one who knew what to do in the first place.


I am 90% finished with my objective but still need to deal with the font size of the TOC. I will post a question about that soon.


Thank you.
















BRGriff is offline   Reply With Quote
Old 06-04-2011, 10:52 PM   #4
kovidgoyal
creator of calibre
kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.
 
kovidgoyal's Avatar
 
Posts: 43,850
Karma: 22666666
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
You're welcome, I firmly believe in teaching a man to fish, as opposed to giving him fish Nothing quite like the feeling of figuring something out for yourself.
kovidgoyal is offline   Reply With Quote
Old 06-06-2011, 11:37 AM   #5
Starson17
Wizard
Starson17 can program the VCR without an owner's manual.Starson17 can program the VCR without an owner's manual.Starson17 can program the VCR without an owner's manual.Starson17 can program the VCR without an owner's manual.Starson17 can program the VCR without an owner's manual.Starson17 can program the VCR without an owner's manual.Starson17 can program the VCR without an owner's manual.Starson17 can program the VCR without an owner's manual.Starson17 can program the VCR without an owner's manual.Starson17 can program the VCR without an owner's manual.Starson17 can program the VCR without an owner's manual.
 
Posts: 4,004
Karma: 177841
Join Date: Dec 2009
Device: WinMo: IPAQ; Android: HTC HD2, Archos 7o; Java:Gravity T
Quote:
Originally Posted by kovidgoyal View Post
You're welcome, I firmly believe in teaching a man to fish, as opposed to giving him fish Nothing quite like the feeling of figuring something out for yourself.
I'll throw my thanks in here as well. Your philosophy of "teach a man to fish" is more than just a philosophy - you actively put it into your work by creating the code development environment, the API, tutorials on use thereof, the recipe system, the plugin system, etc. For all of that - Thanks.
Starson17 is offline   Reply With Quote
Advert
Reply

Tags
code


Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Remove from Archive (book already "deleted" in Amazon account) kindletommy Amazon Kindle 9 08-09-2012 06:17 PM
Orphaned files after "Remove from iTunes device" TheRealRalph Devices 4 04-18-2011 09:13 AM
How do I remove the "Archived" Book shelf from my nook color? leesiulung Nook Color & Nook Tablet 0 02-24-2011 03:02 PM
How to remove "Fully read" books from "Last Open" list? pjeanetta PocketBook 4 12-08-2010 10:30 AM


All times are GMT -4. The time now is 06:00 PM.


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