简体   繁体   English

在feedparser中访问“内容”属性

[英]Accessing “content” attribute in feedparser

I'm using feedparser in Python to parse a remote xml feed. 我在Python中使用feedparser解析远程xml feed。 Results include the typical title/link/published/etc, however there is also a "content" tag that has the following value. 结果包括典型的标题/链接/已发布/等,但是也有一个具有以下值的“内容”标签。 How can I access the value attribute? 如何访问value属性?

[{'base': u'http://url.com', 'type': u'text/html', 'value': u'<p>html text etc', 'language': None}]

I haven't seen any arrays looking like [{}] before. 我以前没有看过任何类似[{}]数组。

That is just a dictionary inside a list. 那只是列表内的字典。 If you have that object as x , just do x[0]['value'] . 如果您将该对象作为x ,则只需执行x[0]['value']

That's a list with one dictionary: 这是一个字典的列表:

print content[0]['value']

From the feedparser documentation : feedparser文档中

entries[i].content

A list of dictionaries with details about the full content of the entry. 词典列表,其中包含有关条目完整内容的详细信息。

Atom feeds may contain multiple content elements. Atom提要可能包含多个内容元素。 Clients should render as many of them as possible, based on the type and the client's abilities. 客户应根据类型和客户的能力提供尽可能多的渲染。

So, you can easily have more dictionaries in that list, or 0. 因此,您可以轻松地在该列表中添加更多的词典,即0。

According to documentation 根据文件

entries[i].content
entries[i].content[j].value
entries[i].content[j].type
entries[i].content[j].language

Etc... 等等...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM