adam eliezerov adam eliezerov - 8 months ago 69
Python Question

Find a word with a for loop - python

What I'm trying to do is have python go over all the RSS feed titles and make the terminal print out only the titles with a certain word.

import feedparser

d = feedparser.parse('')

print d['feed']['title']
print 'number of entries: '
print len(d['entries'])
for post in d.entries:
print post.title + ": "


Your code seems great. What you are missing is an "if" which check if a specific word exists in the post.title

I've used "if" and "in" to filter only the relevant lines.

Details about "in" can be found here:

myword = "NASA" 

for post in d.entries:
  if myword in post.title:
    print post.title