12-01-2010, 02:57 PM | #1 |
Junior Member
Posts: 7
Karma: 10
Join Date: Dec 2010
Device: none
|
How do I replace a common graphic in every story?
Every story I download from the website has a .gif file as a banner, I would like to replace it with another. I have the complete url for both.
Here is my recipe that does not work manner but it didn't work. Code:
class AdvancedUserRecipe1291143841(BasicNewsRecipe): title = u'Poughkeepsipe Journal' oldest_article = 7 max_articles_per_feed = 100 no_stylesheets = True timefmt = ' [%a, %d %b, %Y]' feeds = [(u'Local News', u'http://poughkeepsiejournal.com/apps/pbcs.dll/oversikt?Category=RSS01&mime=xml'), (u'Local Business', u'http://poughkeepsiejournal.com/apps/pbcs.dll/oversikt?Category=RSS02&mime=xml'), (u'Local Sports', u'http://poughkeepsiejournal.com/apps/pbcs.dll/oversikt?Category=RSS03&mime=xml'), (u'Life', u'http://poughkeepsiejournal.com/apps/pbcs.dll/oversikt?Category=RSS04&mime=xml')] masthead_url = 'http://www.poughkeepsiejournal.com/graphics/branding.gif' def print_version(self, url): return url.replace('http://www.poughkeepsiejournal.com', 'http://www.poughkeepsiejournal.com/print') return url.replace('http://www.poughkeepsiejournal.com/graphics/mastlogo.gif','http://www.poughkeepsiejournal.com/graphics/branding.gif') |
12-01-2010, 03:04 PM | #2 |
Wizard
Posts: 4,004
Karma: 177841
Join Date: Dec 2009
Device: WinMo: IPAQ; Android: HTC HD2, Archos 7o; Java:Gravity T
|
|
12-01-2010, 03:54 PM | #3 |
Junior Member
Posts: 7
Karma: 10
Join Date: Dec 2010
Device: none
|
I've tried the method you suggested for removing it, and I've also tried replacing it. But I think I am getting something wrong with the syntax. The whole story gets deleted.
Here is specifically what I need to have removed, or replaced from the story. Code:
<div style="background-image:url(/gci/gc/p15/background_sprite.gif);background-color:transparent;background-position:-3000px 0;"> <img src="/graphics/mastlogo.gif" alt=www.poughkeepsiejournal.com border="0" > </div> |
12-01-2010, 04:50 PM | #4 | |
Wizard
Posts: 4,004
Karma: 177841
Join Date: Dec 2009
Device: WinMo: IPAQ; Android: HTC HD2, Archos 7o; Java:Gravity T
|
Quote:
remove_tags = [dict(name='img', attrs={'src':'/graphics/mastlogo.gif'})] |
|
12-02-2010, 08:21 AM | #5 |
Junior Member
Posts: 7
Karma: 10
Join Date: Dec 2010
Device: none
|
Thanks - another question
Starson - thanks, that worked great. I will post the recipe and I would like to learn more. I've looked over the tutorial and command reference, but I still cannot figure out how to put together the syntax to swap one graphic for another. Could you help with that?
|
12-02-2010, 08:53 AM | #6 |
Wizard
Posts: 4,004
Karma: 177841
Join Date: Dec 2009
Device: WinMo: IPAQ; Android: HTC HD2, Archos 7o; Java:Gravity T
|
I'd use preprocess_html, as originally suggested. You were using the replace function, and that should work, or use ReplaceWith on the tag. Preprocess_html is called before the soup is parsed for links and images.
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Problems Common to All Kobos | Nicktheviking | Kobo Reader | 15 | 10-25-2010 10:35 PM |
Common Problems | Edd | Sony Reader | 0 | 05-26-2009 01:36 AM |
Common Problems | Edd | Sony Reader | 0 | 05-26-2009 01:34 AM |
eBook piracy, how common is it? | Stringer | News | 920 | 05-01-2009 10:33 AM |