【发布时间】:2021-04-10 02:50:09
【问题描述】:
我正在作为一个 Python 新手练习在 Python 中导入数据。最终,我想通过将数据放入一个连贯的数据框中,使用 NLP 来分析来自不同播客的数据(播客本身的信息和)。
到目前为止,我已经设法阅读了一个 RSS 提要列表,并获得了有关 RSS 提要(一篇帖子)每一集的信息。
但是我很难在 python 中找到一个集成的工作进程来收集两者
- RSS 提要(帖子)每一集的信息
- 和有关 RSS 提要的一般信息(如播客的标题) 一口气。
代码 这就是我目前所得到的
import feedparser
import pandas as pd
rss_feeds = ['http://feeds.feedburner.com/TEDTalks_audio',
'https://joelhooks.com/rss.xml',
'https://www.sciencemag.org/rss/podcast.xml',
]
#number of feeds is reduced for testing
posts = []
feed = []
for url in rss_feeds:
feed = feedparser.parse(url)
for post in feed.entries:
posts.append((post.title, post.link, post.summary))
df = pd.DataFrame(posts, columns=['title', 'link', 'summary'])
输出 数据框包括三列的 652 个非空对象(如预期的那样) - 基本上是每个播客中的每个帖子。 title 列是指剧集的标题,但 不是 是指播客的标题(在本例中为“Ted Talk Daily”)。
| title | link | summary | |
|---|---|---|---|
| 0 | 3 questions to ask yourself about everything y... | https://www.ted.com/talks/stacey_abrams_3_ques... | How you respond to setbacks is what defines yo... |
| 1 | What your sleep patterns say about your relati... | https://www.ted.com/talks/tedx_shorts_what_you... | Wendy Troxel looks at the cultural expectation... |
| 2 | How we can actually pay people enough -- with ... | https://www.ted.com/talks/ted_business_how_we_... | Capitalism urgently needs an upgrade, says Pay... |
我也在努力寻找一种方法来将播客的标题包含到这个数据框中。我总是在选择整个提要信息的部分时出错,例如['feed']['title'].
感谢您的每一个提示!
来源 到目前为止,我已经习惯了基于此来源的内容:Get Feeds from FeedParser and Import to Pandas DataFrame
【问题讨论】:
-
一些提要根本没有关于播客磁贴的任何属性。
-
是否可以为每个 url 创建一个字典?
-
@ABC 感谢您指出这一点。用户 perl 的评论也消除了困惑。这就是答案。
标签: python pandas rss feedparser