Django-yarr의 RSS URL에서 콘텐츠 및 이미지 가져 오기
-
21-12-2019 - |
문제
저는 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
.
"Nofollow"> BeautifulSoup , lxml 또는 ElementTree 데이터를 처리하려면 (또는 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()
.
에서 각 기사를 잡을 수 있습니다.
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')
. 제휴하지 않습니다 StackOverflow