如何在python中解析xml rss提要内容

  • 本文关键字:rss xml python python urllib
  • 更新时间 :
  • 英文 :


我有福克斯新闻的rss提要,我需要使用tkinter显示文章的标题以及日期和时间。

def fox_news():
fox_news = download('https://moxie.foxnews.com/google-publisher/latest.xml')
title = re.compile("title").search(fox_news)
print(title)

您可以使用提要解析器

只需安装即可:pip install feedparser

一切就绪:

import feedparser

def fox_news():
feed = feedparser.parse('https://moxie.foxnews.com/google-publisher/latest.xml')

for entry in feed.entries:
title = entry.title
published = entry.published_parsed

print(published)
print(title)
print()

fox_news()

结果:

time.struct_time(tm_year=2022, tm_mon=10, tm_mday=25, tm_hour=2, tm_min=0, tm_sec=56, tm_wday=1, tm_yday=298, tm_isdst=0)
Some news title 1
time.struct_time(tm_year=2022, tm_mon=10, tm_mday=25, tm_hour=1, tm_min=57, tm_sec=50, tm_wday=1, tm_yday=298, tm_isdst=0)
Some news title 2
time.struct_time(tm_year=2022, tm_mon=10, tm_mday=25, tm_hour=1, tm_min=49, tm_sec=18, tm_wday=1, tm_yday=298, tm_isdst=0)
Some news title 3

相关内容

  • 没有找到相关文章

最新更新