我将尝试使用不同的Python3模块和网络文章来解析XML,但是一直没有成功。以下是我要解析的XML内容:
```html
我需要从XML标签中获取数据:名称和值。 应该是这样的:
我该如何使用Python3获取这些值(最好使用Python默认模块-而不是bs4)?
谢谢。
```html
我有这个XML:
```<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" xmlns:cwmp="urn:dslforum-org:cwmp-1-0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"><SOAP-ENV:Header/>
<SOAP-ENV:Body SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
<cwmp:GetParameterValuesResponse>
<ParameterList SOAP-ENC:arrayType="cwmp:ParameterValueStruct[3]">
<ParameterValueStruct>
<Name>SOME_NAME_1_HERE</Name>
<Value>2</Value>
</ParameterValueStruct>
<ParameterValueStruct>
<Name>SOME_NAME_2_HERE</Name>
<Value>180</Value>
</ParameterValueStruct>
<ParameterValueStruct>
<Name>SOME_NAME_3_HERE</Name>
<Value>1800</Value>
</ParameterValueStruct>
</ParameterList>
</cwmp:GetParameterValuesResponse>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
我需要从XML标签中获取数据:名称和值。 应该是这样的:
SOME_NAME_1_HERE 2
SOME_NAME_2_HERE 180
SOME_NAME_3_HERE 1800
我该如何使用Python3获取这些值(最好使用Python默认模块-而不是bs4)?
谢谢。
findall()
会受到元素的xmlns
属性的影响。因此,请确保您的元素具有有效的xmlns
属性,如果这对您不起作用。 - micka190