adam eliezerov adam eliezerov - 1 year ago 99
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 + ": "

Answer Source

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
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download