我正在尝试为海盗湾电影 RSS 提要制作一个过滤器,它过滤掉我已经获得的电影并保留我目前没有的电影。稍后它将从提供的磁力链接下载 torrent。问题是我不知道如何从我没有的电影中过滤掉我拥有的电影,因为我试图从一个字符串中过滤一个列表,但不知道如何绕过它。这是一个可运行的示例,其中包含我想在注释中添加的代码:import feedparserimport sslif hasattr(ssl, '_create_unverified_context'): ssl._create_default_https_context = ssl._create_unverified_contextfeed = feedparser.parse('https://thepiratebay.org/rss/top100/207')feed_title = feed['feed']['title']feed_entries = feed.entriesf = 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)电影.txt文件:aquamanspiderman
2 回答

慕斯王
TA贡献1864条经验 获得超2个赞
您可以尝试以下操作:
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')
添加回答
举报
0/150
提交
取消