我有一个从RSS提要返回图像URL的函数(我使用的是feedparser)。问题是它返回一个奇怪的格式列表
我的提要有一个名为media_content
的键。用于访问它的代码是
import feedparser
NewsFeed = feedparser.parse("https://thegroovecartel.com/feed/")
entry = NewsFeed.entries[0]
post_image = entry.media_content
现在,出于某种原因,post_image是一个1元素格式的列表,如下所示:
[{'url': 'https://thegroovecartel.com/i1.wp.com/thegroovecartel.com/wp-content/uploads/2020/10/KAYYA.jpg?fit=300%2C237&ssl=1', 'medium': 'image'}]
现在,我不明白如何访问实际的URL字段,将https://thegroovecartel.com/i1.wp.com/thegroovecartel.com/wp-content/uploads/2020/10/KAYYA.jpg?fit=300%2C237&ssl=1
作为字符串放入变量中
您必须将
post_image
视为一个列表,评估它的第一个元素(即索引为0的元素),为您提供包含图像属性的字典相关问题 更多 >
编程相关推荐