Analyzing Android manifest file for uses-permission tag using python

I am analyzing the use-permission tag in the xml file (androidmanifest.xml) mentioned in the android application.

I tried to implement a for loop to make it iterative, but I failed, and here it is

Python:

from xml.dom.minidom import parseString file = open('/root/Desktop/AndroidManifest.xml','r') data = file.read() file.close() dom = parseString(data) xmlTag = dom.getElementsByTagName('uses-permission')[0].toxml() print xmlTag 

Output:

  <uses-permission android:name="android.permission.INTERNET"> </uses-permission> 

for loop error:

 for uses-permission in xmlTag: #print child.tag, child.attrib print xmlTag.tag xmlTag = dom.getElementsByTagName('uses-permission')[1].toxml() xmlTag= dom._get_childNodes #print xmlTag 
+4
source share
1 answer

To find all permission tags, try iterating over the nodes that dom.getElementsByTagName('uses-permission') returns instead of accessing only the node at index 0 :

 from xml.dom.minidom import parseString data = '' with open('/root/Desktop/AndroidManifest.xml','r') as f: data = f.read() dom = parseString(data) nodes = dom.getElementsByTagName('uses-permission') # Iterate over all the uses-permission nodes for node in nodes: print node.toxml() 

or if you want only permission, not xml, you can replace node.toxml() with node.getAttribute('android:name') .

+3
source

All Articles