如何查找与列表中的项匹配的多个字符串中的项

问题描述 投票:0回答:2

嗨,我正在尝试为piratebay电影rss feed制作一个过滤器,它过滤掉我已经获得的电影,并保留我目前没有的电影。然后它将从提供的磁力链接下载torrent。问题是我无法弄清楚如何过滤掉我没有的电影,因为我试图从字符串中过滤一个列表并且不知道解决方法。这是一个可运行的示例,其中包含我想要添加到注释中的代码:

import feedparser
import ssl

if hasattr(ssl, '_create_unverified_context'):
    ssl._create_default_https_context = ssl._create_unverified_context
feed = feedparser.parse('https://thepiratebay.org/rss/top100/207')
feed_title = feed['feed']['title']
feed_entries = feed.entries
f = open("movies.txt", "r+")
fr = f.readlines()
print(fr)
for entry in feed.entries[:25]:
    el = entry.title.lower()
    # if fr in el:
        # remove_from_titles()
    # else:
    article_title = el
    article_link = entry.link
    print(article_title)
    print(article_link)

movies.txt文件:

aquaman
spiderman
python feedparser
2个回答
0
投票

尝试使用set而不是list。如果Feed集是A而文件标题B那么A中不在B中的标题是A.difference(B)


0
投票

你能尝试以下方法吗?

with open("movies.txt", "r+") as f:
    fr = f.readlines()
if article_title.lower() not in movies_list:
    print(article_title)
    # do your downloading stuff here

    # update your movies.txt file
    with open("movies.txt", "a") as f:
        f.write('\n' + 'article_title')
© www.soinside.com 2019 - 2024. All rights reserved.