我需要提取标签之间的数据,如下所述。另外,如果数据对应于相同的id,我想连接数据
例如,根据下面的XML,两个标记都位于对应于相同id“00F1234A”的选项卡内 因此,需要提取“Hello World”
xml_string="
<w:r w:rsid="00F1234A">
<w:rPr>
</w:rPr>
<w:t>Hello</w:t>
</w:r>
<w:r w:rsid="00F1234A">
<w:rPr>
</w:rPr>
<w:t xml:space="preserve">World</w:t>
</w:r>"
目前,我正在使用以下正则表达式在标记之间提取数据
re.findall("<w:t>(.+?)</w:t>",xml_string)
这给了我你好,但不是你好世界
如何连接与相同id(在本例中为“00F1234A”)对应的中的数据
为了解析它,您需要XML(
xmlns: x = "urn:something"
)中的名称空间使用etrees提取值,而不是像这样使用正则表达式:
也请查看this post
相关问题 更多 >
编程相关推荐