View Single Post
Old 10-18-2020, 12:35 PM   #1
epubli
Enthusiast
epubli began at the beginning.
 
Posts: 25
Karma: 10
Join Date: Nov 2012
Device: Pocketbook Inkpad 3
How to remove an article which contains "this article was sponsored" in the text ?

Some feeds have articles which contain advertisements. I would like to remove the articles from the feed based on some string in the content like "this article was sponsored by".

How can this be achieved ?


Up to I tried to check the article content in parse_feeds() but this does not work. I think there is not yet anything in article.content:

Spoiler:

def parse_feeds(self):
# Call parent's method.
feeds = BasicNewsRecipe.parse_feeds(self)
# Loop through all feeds.
for feed in feeds:
# Loop through all articles in feed.
for article in feed.articles[:]:
# Remove sponsored articles
if 'this article was sponsored' in article.content:
feed.articles.remove(article)
return feeds


Any help is appreciated.
epubli is offline   Reply With Quote