【问题标题】:Python and RSS feeds - parse feederPython 和 RSS 提要 - 解析提要
【发布时间】:2016-09-16 13:52:11
【问题描述】:

我在 python 中使用 feed 解析器,我是 python 的初学者。

for post in d.entries:
    if test_word3 and test_word2 in post.title:
        print(post.title)

我要做的是让提要解析器在 RSS 提要的标题中找到几个单词。

【问题讨论】:

标签: python parsing rss feed feedparser


【解决方案1】:

请注意,and 不会分布在 in 运算符中。

if test_word3 in post.title and
   test_word2 in post.title:

应该可以解决您的问题。你写的被评价为

if test_word3 and (test_word2 in post.title):

...这变成了...

if (test_word3 != "") and (test_word2 in post.title):

简化一点... 字符串的布尔值是它是否为非空。 整数的布尔值是不是非零。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-08-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多