使用美丽的汤无法获得标签的价值

时间:2017-10-27 15:28:39

标签: xml python-2.7 beautifulsoup

使用python代码我无法从名称标签中获取值ethernet1 / 1?它只返回值条目

<response status="success">
<result>
<hw>
<entry>
<name>ethernet1/1</name>
<duplex>full</duplex>
<type>0</type>
<state>up</state>
<st>1000/full/up</st>
<mac>00:1s:15:22:05:45</mac>
<mode>(autoneg)</mode>
<speed>1000</speed>
<id>16</id>
</entry>


for interface in hwintmarkup.find_all("entry"):
    interfaced={'name':interface.name,
                'duplex':str(interface.duplex.get_text()),
                'state':str(interface.state.get_text()),
                'mac':str(interface.mac.get_text()),
                }

1 个答案:

答案 0 :(得分:1)

name是保留变量以获取当前标记名称。你必须使用这样的东西:

interface.find('name')