我正在使用django-yarr为我的RSS阅读器应用程序。是否有任何方法可以从RSS URL获取内容并在数据库中保存? 或者有任何可以做到这一点的图书馆吗?

提前感谢

有帮助吗?

解决方案

您是否正在寻找从RSS读取数据,处理它并保存它?

使用请求获取数据。

import requests

req = requests.get('http://feeds.bbci.co.uk/news/technology/rss.xml')
reg.text // XML as a string
.

beautifuesoup lxml 元素reree 处理数据(或可以处理XML的类似库)

from bs4 import BeautifulSoup
soup = BeautifulSoup(req.text)

images = soup.findAll('media:thumbnail')
.

终于用数据来做任何你想要的东西

for image in images:
    thing = DjangoModelThing()
    thing.image = image.attrs.get('url')
    thing.save()
.

更新

或者,您可以从RSS中获取每篇文章

articles = soup.findAll('item')

for article in articles:
    title = article.find('title')
    description = article.find('description')
    link = article.find('link')
    images = article.find('media:thumbnail')
.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top