嗨,我正在尝试为piratebay电影rss feed过滤,该过滤器会过滤掉我已经购买的电影,并保留我目前没有的电影。然后,它将稍后从提供的磁铁链接下载种子。问题是我不知道如何从我没有的电影中过滤掉我的电影,因为我试图从字符串中过滤列表并且不知道解决方法。这是一个可运行的示例,其中包含我要在注释中添加的代码:
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
答案 0 :(得分: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')
答案 1 :(得分:0)
尝试使用set而不是list。如果供稿集为 A ,文件标题为 B ,则A中不在B中的标题为A.difference(B)