[英]Retrieving url from feedparser media:content
The following code works fine: 以下代码可以正常工作:
if 'media_content' in entry:
mediaContent=entry.media_content
else:
mediaContent='No Media'
But this gives me an error: 但这给我一个错误:
if 'media_content' in entry:
mediaContent=entry.media_content['url']
else:
mediaContent='No Media'
This is the error: 这是错误:
list indices must be integers, not str
I've seen multiple uses of this syntax when searching on the web to pull out the url from the media_content element of feedparser, but it isn't working for me. 在网络上搜索从feedparser的media_content元素中提取URL时,我已经看到了这种语法的多种用法,但是它对我不起作用。 I'm new to python, so I'm sure it is just that I'm not accessing the dictionary properly.
我是python的新手,所以我确定这只是我没有正确访问字典。 I just want the raw url as a string.
我只想要原始网址作为字符串。
Thanks! 谢谢!
entry.media_content
is a list of entries, each a dictionary: entry.media_content
是条目列表 ,每个词典:
for item in entry.media_content:
print item['url']
You could just grab the first one listed: 您可以仅获取列出的第一个:
if 'media_content' in entry:
mediaContent = entry.media_content[0]['url']
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.