簡單寫了一個python腳本記錄一下Mainfest中Activity的相關信息,代碼以下:python
#!/usr/bin/python # -*- coding: UTF-8 -*- import xml.etree.ElementTree as ET import pandas as pd preix="{http://schemas.android.com/apk/res/android}" def parseXml(filePath): tree=ET.parse(filePath) # print(tree.getroot().attrib) root=tree.getroot() activitylist=[] noScreenRotateList=[] for application in root: if(application.tag == "application"): for element in application.findall("activity"): name= element.get(preix+'name') configChange=element.get(preix+"configChanges") if(configChange == None): noScreenRotateList.append({name:configChange}) else: activitylist.append({name:configChange}) activitylist=activitylist+noScreenRotateList buildTable(activitylist) def buildTable(list): a = [] b = [] for item in list: for key in item: a.append(key) b.append(item[key]) dit = {'Activity':a, 'ConfigChangeOptions':b} file_path = r'output.xlsx' writer = pd.ExcelWriter(file_path) df = pd.DataFrame(dit) #columns參數用於指定生成的excel中列的順序 df.to_excel(writer, columns=['Activity','ConfigChangeOptions'], index=False,encoding='utf-8',sheet_name='Sheet') writer.save() parseXml("AndroidManifest.xml")
最終輸出結果爲一個excel表格文件,裏面記錄了Activity的個數以及對象ConfigChanges參數的值android