我有一个文件有多个文件标签。每个doc标签中都有一个docID标签。如果docID标签匹配的话,我需要把所有东西都放在doc标签里。
我使用HTMLparser来解析文件。
所以我需要做的是:
1号。递归地迭代所有文档标记。
2。对于每个doc标记,如果其中的docID标记匹配,则获取doc标记下的所有内容。
三。对所有文档标签重复第2步。你知道吗
def get_docs(self, filepaths):
parser = etree.HTMLParser()
for file in filepaths:
tree = etree.parse(file, parser)
# tree = etree.parse(file)
doc = tree.findall('.//doc')
for elem in doc:
print etree.tostring(elem)
我当前正在尝试获取每个doc标记中的内容,但text\u content()失败。我在做这件事时犯了错误
属性错误:'lxml.etree文件“.\u Element”对象没有“text\u content”属性
目前没有回答
相关问题 更多 >
编程相关推荐