Python reddit的feedparser返回空

Python reddit的feedparser返回空,python,rss,feedparser,Python,Rss,Feedparser,我正在尝试将feedparser与python一起使用,从sub_reddit获取最新的帖子 我有下面的代码,但当我运行它时,它不会返回任何东西 import feedparser feed = feedparser.parse("http://www.reddit.com/r/funny/new/.rss") #feed = feedparser.parse("http://feeds.bbci.co.uk/news/england/london/rss.xml") feed_entrie

我正在尝试将feedparser与python一起使用,从sub_reddit获取最新的帖子

我有下面的代码,但当我运行它时,它不会返回任何东西

import feedparser

feed = feedparser.parse("http://www.reddit.com/r/funny/new/.rss")
#feed = feedparser.parse("http://feeds.bbci.co.uk/news/england/london/rss.xml")

feed_entries = feed.entries

for entry in feed.entries:
    article_title = entry.title
    article_link = entry.link
    article_published_at = entry.published # Unicode string
    article_published_at_parsed = entry.published_parsed # Time object
    print (article_title)

我认为这与前一条关于feedparser解析HTTPS RSS提要的SSL问题相关-

添加以下代码可以解决SSL问题:

import ssl
if hasattr(ssl, '_create_unverified_context'):
    ssl._create_default_https_context = ssl._create_unverified_context
例如,在代码中:

import feedparser
import ssl
if hasattr(ssl, '_create_unverified_context'):
    ssl._create_default_https_context = ssl._create_unverified_context
feed = feedparser.parse("http://www.reddit.com/r/funny/new/.rss")
#feed = feedparser.parse("http://feeds.bbci.co.uk/news/england/london/rss.xml")

feed_entries = feed.entries
for entry in feed.entries:
    article_title = entry["title"]
    article_link = entry["link"]
    print(f"{article_title}: {article_link}")

您可能需要检查每个条目使用的密钥-发布的密钥似乎不是其中之一,因此我在示例中删除了它。

我认为这与前一个条目有关,该条目涉及feedparser解析HTTPS RSS提要时的SSL问题-

添加以下代码可以解决SSL问题:

import ssl
if hasattr(ssl, '_create_unverified_context'):
    ssl._create_default_https_context = ssl._create_unverified_context
例如,在代码中:

import feedparser
import ssl
if hasattr(ssl, '_create_unverified_context'):
    ssl._create_default_https_context = ssl._create_unverified_context
feed = feedparser.parse("http://www.reddit.com/r/funny/new/.rss")
#feed = feedparser.parse("http://feeds.bbci.co.uk/news/england/london/rss.xml")

feed_entries = feed.entries
for entry in feed.entries:
    article_title = entry["title"]
    article_link = entry["link"]
    print(f"{article_title}: {article_link}")
您可能需要检查每个条目使用的键-published似乎不是其中之一,因此我在示例中删除了它。

考虑更改:

article_published_at = entry.published # Unicode string
article_published_at_parsed = entry.published_parsed # Time object
致:




还要确保使用
https
协议,以防
feedparser
不遵循
http
https
正确重定向。

考虑更改:

article_published_at = entry.published # Unicode string
article_published_at_parsed = entry.published_parsed # Time object
致:




还要确保您使用了
https
协议,以防
feedparser
不遵循
http
->
https
正确重定向