从django-yarr中的RSS URL获取内容和图像

问题描述 投票:1回答:1

我正在将django-yarr用于我的RSS阅读器应用程序。有什么方法可以从RSS URL获取内容并将其保存在数据库中?还是有图书馆可以做到这一点?

django rss-reader
1个回答
3
投票

您是否正在从RSS中读取数据,进行处理并保存?

使用Requests获取数据。

import requests

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

[BeautifulSouplxmlElementTree以处理数据(或可以处理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()

UPDATE

或者,您可以从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')
© www.soinside.com 2019 - 2024. All rights reserved.