我的烧瓶应用程序给出了“设置”错误,我一直在编写RSS feed网络应用程序的代码,但目前有一个我无法弄清的错误;这是我的代码:
import feedparser
from flask import Flask
from flask import render_template
app = Flask(__name__)
RSS = {"http://feeds.bbci.co.uk/news/rss.xml",
"http://rss.iol.io/iol/news", "http://feeds.foxnews.com/foxnews/latest", "http://rss.cnn.com/rss/edition.rss"}
#error occurs here
@app.route("/")
@app.route("/<publication>")
def get_news(publication="bbc"):
#ERROR OCCURS HERE
feed = feedparser.parse(RSS[publication])
first_article = feed['entries'][0]
return render_template("home.html",
title=first_article.get("title"),
published=first_article.get("publication"),
summary=first_article.get("summary"))
if __name__ == "__main__":
app.run(debug=True, port=5000)
Run Code Online (Sandbox Code Playgroud)
我在这两行出现错误
feed = feedparser.parse(RSS[publication])
first_article = feed['entries'][0]
Run Code Online (Sandbox Code Playgroud)
无法找出实际错误
正如Iron Fist指出的那样,它RSS是一个集合(不可下标),尽管看起来好像您正在尝试将其用作字典。根据您用于的默认值get_news,我冒昧地猜测您想要这样的东西:
RSS = {"bbc": "http://feeds.bbci.co.uk/news/rss.xml",
"iol": "http://rss.iol.io/iol/news",
"fox": "http://feeds.foxnews.com/foxnews/latest",
"cnn": "http://rss.cnn.com/rss/edition.rss"}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
26995 次 |
| 最近记录: |