用 for 循环查找单词 - python
Find a word with a for loop - python
我想做的是 python 遍历所有 RSS 提要标题,让终端只打印出带有特定单词的标题。
import feedparser
d = feedparser.parse('http://rss.cnn.com/rss/edition_technology.rss')
print d['feed']['title']
print 'number of entries: '
print len(d['entries'])
for post in d.entries:
print post.title + ": "
你的代码看起来很棒。
您缺少的是一个 "if" ,它检查 post.title
中是否存在特定单词
我已使用 "if" 和 "in" 仅过滤相关行。
有关 "in" 的详细信息可在此处找到:http://www.jworks.nl/2013/11/07/python-goodness-the-in-keyword/
myword = "NASA"
for post in d.entries:
if myword in post.title:
print post.title
我想做的是 python 遍历所有 RSS 提要标题,让终端只打印出带有特定单词的标题。
import feedparser
d = feedparser.parse('http://rss.cnn.com/rss/edition_technology.rss')
print d['feed']['title']
print 'number of entries: '
print len(d['entries'])
for post in d.entries:
print post.title + ": "
你的代码看起来很棒。 您缺少的是一个 "if" ,它检查 post.title
中是否存在特定单词我已使用 "if" 和 "in" 仅过滤相关行。
有关 "in" 的详细信息可在此处找到:http://www.jworks.nl/2013/11/07/python-goodness-the-in-keyword/
myword = "NASA"
for post in d.entries:
if myword in post.title:
print post.title