07-20-2011, 02:24 PM | #1 |
Connoisseur
Posts: 83
Karma: 499304
Join Date: Jul 2011
Device: Kindle
|
Easiest way to add arbitrary HTML to every article?
Hello! I am working on a recipe and need to prepend a title (<h1> tags in html) before every article, but I have found this is not as common of a problem as I anticipated.
What is the easiest way to prepend arbitrary HTML to a finished article? I need to be able to inject it before a certain div inside the processed HTML. |
07-20-2011, 02:42 PM | #2 | |
Wizard
Posts: 4,004
Karma: 177841
Join Date: Dec 2009
Device: WinMo: IPAQ; Android: HTC HD2, Archos 7o; Java:Gravity T
|
Quote:
http://www.crummy.com/software/Beaut...mentation.html |
|
Advert | |
|
07-20-2011, 02:44 PM | #3 |
Connoisseur
Posts: 83
Karma: 499304
Join Date: Jul 2011
Device: Kindle
|
I did figure this one out myself, sort of. I settled with adding the title into the content container (it makes no difference when viewed anyway.)
It's done by using postprocess_html(), which gives you the HTML of each article just before heading to the finished paper. Code:
def postprocess_html(self, soup, first_fetch): #find container, in my case it's a div with the id attribute set to "story" and insert the HTML you wish, in my case the string '<h1>testing</h1>' for link_tag in soup.findAll(attrs={"id" : "story"}): link_tag.insert(0,'<h1>testing</h1>') |
07-20-2011, 02:49 PM | #4 | |
Resident Curmudgeon
Posts: 73,897
Karma: 128597114
Join Date: Nov 2006
Location: Roslindale, Massachusetts
Device: Kobo Libra 2, Kobo Aura H2O, PRS-650, PRS-T1, nook STR, PW3
|
Quote:
|
|
07-20-2011, 04:20 PM | #5 | |
Connoisseur
Posts: 83
Karma: 499304
Join Date: Jul 2011
Device: Kindle
|
Quote:
The articles I'm getting do not have any heading, the heading is only existent in the <title> tag of the document, so articles are displayed without a heading. Here's an example: With my fix, I can add a big text to all the articles with the help of the h1 tag. Last edited by khromov; 07-20-2011 at 04:23 PM. |
|
Advert | |
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Easiest way to start creating .mobi from HTML using C#? | jonj | Kindle Formats | 9 | 12-10-2011 11:30 AM |
How to add my own html page to recipe | naisren | Recipes | 3 | 11-17-2010 04:37 PM |
Add book as HTML file | Mister_R | Calibre | 5 | 10-19-2010 10:43 AM |
Unable to add HTML files in 0.6.10 | nekokami | Calibre | 2 | 09-06-2009 11:17 AM |
What's the easiest way to get a book on the kindle from TXT or HTML? | QU2C371FcY | Amazon Kindle | 7 | 05-27-2009 08:55 AM |