[python] XML strom a XPath

Stone phracek2 na gmail.com
Pátek Srpen 19 10:38:25 CEST 2011


Aho vsichni mam jeden problem.

Mam XML soubor, ktery vypada asi takto:
<?xml version="1.0" ?>
<?xml-stylesheet href="only_up.xsl" type="text/xsl"?>
<!-- Nmap 4.75 scan initiated Fri Aug 19 09:12:01 2011 as: nmap -v -sP
-oX new_scan.xml --stylesheet only_up.xsl 10.6.0.0/16 -->
<nmaprun scanner="nmap" args="nmap -v -sP -oX new_scan.xml --
stylesheet only_up.xsl 10.6.0.0/16" start="1313737921" startstr="Fri
Aug 19 09:12:01 2011" version="4.75" xmloutputversion="1.02">
<host><status state="down" reason="no-response"/>
<address addr="10.6.0.0" addrtype="ipv4" />
</host>
<host><status state="down" reason="no-response"/>
<address addr="10.6.0.1" addrtype="ipv4" />
</host>
<host><status state="down" reason="no-response"/>
<address addr="10.6.0.2" addrtype="ipv4" />
</host>
<host><status state="up" reason="no-response"/>
<address addr="10.6.0.3" addrtype="ipv4" />
</host>
<host><status state="up" reason="no-response"/>
<address addr="10.6.0.4" addrtype="ipv4" />
</host>
</nmap>

Pomoci Pythonu to delam takto, ale stale to hlasi chybu:
#!/usr/bin/python

from xml.etree import ElementTree

xmltree = ElementTree.parse("/home/user/djcode/testlab/last_scan.xml")
'''host = xmltree.findall('host')'''
host = xmltree.findall('///status[@state=\'up\']/parent::*')
print len(host)

To mi ale hlasi chybu:
    "expected path separator (%s)" % (op or tag)

Diky za rady


Další informace o konferenci Python