我制作了一個(gè)新聞抓取工具,它獲取名為“Phoronix”的網(wǎng)站的 RSS 提要并將其保存在文本文件中。但由于某種原因,它獲得了第二篇最新文章而不是最新文章。這是代碼:import feedparserimport timedef Log(): f = open("Logs/phoronixdb.txt", "a") f.write("\n") f.write("\n" + entry.published) f.write("\n") f.write("\n" + entry.title) f.write("\n") f.write("\n" + entry.summary) f.write("\n") f.write("\n" + entry.link) f.close()def CheckDate(): f2 = open("db/phoronixlastdate.txt", "r") date = f2.read() if date == entry.published: f2.close() else: Log() f2.close() f2 = open("db/phoronixlastdate.txt", "w") f2.write(entry.published) f2.close()while True: NewsFeed = feedparser.parse("https://www.phoronix.com/rss.php") entry = NewsFeed.entries[1] CheckDate() time.sleep(5)
News Scraper 總是得到第二篇最新文章而不是最新文章
慕尼黑5688855
2022-10-25 09:43:33