Python-从plist/xml中提取信息

Python-从plist/xml中提取信息,python,Python,这是我的plist/xml(我把它缩短了一点,但它仍然很大,所以我把它作为一个链接: 我要做的是提取如下字段: appIdentifier 类名 作用 你能试试上面的代码片段吗,希望对你有所帮助 您可以尝试上面的代码片段吗,希望这有帮助,因为现代XML库支持XPath,所以这更容易;因此,我将使用下面的代码片段 全部输出为: App:com.apprizon.follow4followapp;类:IBINappurchasesManager;方法:-(bool)isPremium App:com

这是我的plist/xml(我把它缩短了一点,但它仍然很大,所以我把它作为一个链接:

我要做的是提取如下字段:

appIdentifier
类名
作用 你能试试上面的代码片段吗,希望对你有所帮助


您可以尝试上面的代码片段吗,希望这有帮助,因为现代XML库支持XPath,所以这更容易;因此,我将使用下面的代码片段

全部输出为:

App:com.apprizon.follow4followapp;类:IBINappurchasesManager;方法:-(bool)isPremium
App:com.apprizon.follow4followapp;类:IBRedeemCodeView;方法:-(无符号长-长)奖励
App:com.apprizon.follow4followapp;类:IBGetFollowersGoldenFollowersCell;方法:-(void)setFreeFollowers:(long-long)
App:com.apprizon.follow4followapp;类:IBGetFollowersGoldenFollowersCell;方法:-(长-长)freeFollowers
App:com.apprizon.follow4followapp;类:IBSettings;方法:-(双精度)额外报酬ForPro
App:com.apprizon.follow4followapp;类:IBSettings;方法:-(void)setReferralMinReward:(long)
App:com.apprizon.follow4followapp;类:IBSettings;方法:-(长-长)referralMinReward
App:com.apprizon.follow4followapp;类:IBSettings;方法:-(void)setRewardForSecondaryAccount:(long)
App:com.apprizon.follow4followapp;类:IBSettings;方法:-(长-长)rewardForSecondaryAccount
App:com.apprizon.follow4followapp;类:IBSettings;方法:-(void)setextrawardforpro:(double)
App:com.apprizon.follow4followapp;类:IBMe;方法:-(无符号长-长)availableSpins
App:com.apprizon.follow4followapp;类:IBMe;方法:-(bool)cancode
App:com.apprizon.follow4followapp;类:IBMe;方法:-(void)setCanRedemption代码:(bool)
App:com.apprizon.follow4followapp;类:IBSettings;方法:-(bool)wofFreeSpinsEnabled
App:com.apprizon.follow4followapp;类:IBSettings;方法:-(void)setWofFreeSpinsEnabled:(bool)
App:com.apprizon.follow4followapp;类:IbWheelofFutureView;方法:-(长)numberOfFreePins
App:com.apprizon.follow4followapp;类:IbWheelofFutureView;方法:-(void)setNumberOfFreeSpins:(长)
App:com.apprizon.follow4followapp;类:IbWheelofFuturePrizeView;方法:-(bool)freeSpinAvailable
App:com.apprizon.follow4followapp;类:IbWheelofFuturePrizeView;方法:-(void)setFreeSpinAvailable:(bool)
App:com.apprizon.follow4followapp;类:IbWheelofFutureManager;方法:-(bool)freeSpinAvailable
App:com.apprizon.follow4followapp;类:IBMiniGame;方法:-(void)setPrize:(id)
App:com.apprizon.follow4followapp;类别:iBMiGame;方法:-(id)奖品
App:com.apprizon.follow4followapp;类:IBSettings;方法:-(无符号长-长)maxEnergyDefault
App:com.apprizon.follow4followapp;类:IBSettings;方法:-(void)setMaxEnergyDefault:(无符号长)
App:com.betternet;类:BetternetUser;方法:-(bool)isPremium
App:com.betternet;类:BetternetUser;方法:-(void)setIsPremium:(bool)
App:com.betternet;类:BetternetUser;方法:-(bool)allowedPremium
App:com.betternet;类:GADDevice;方法:-(bool)越狱
App:com.betternet;类:FlurryUtil;方法:+(BOOL)设备故障
App:co.allconnected.vpnmaster;类:FlurryUtil;方法:+(BOOL)设备故障
App:com.anchorfree.hss;类别:ZDKUser;方法:-(bool)isAgent
App:com.anchorfree.hss;类别:AFUserAccount;方法:-(void)设置自动更新:(bool)
App:com.anchorfree.hss;类别:AFUserAccount;方法:-(bool)自动续费
App:com.anchorfree.hss;类:AFUserAccount;方法:-(void)setIsValid:(bool)
App:com.apprizon.follow4followapp;类:IBINappurchasesManager;方法:-(bool)isPremium
App:com.alphaweb.fairyfail;类:IBBearGood;方法:-(浮点)速度
App:com.alphaweb.fairyfail;类:游戏场景;方法:-(int)totalNumberOfStars
App:com.alphaweb.fairyfail;类:气球精灵;方法:-(浮动)速度
App:com.alphaweb.fairyfail;类:游戏场景;方法:-(BOOL)rateMenuShouldBeDisplayed
App:com.alphaweb.fairyfail;类:游戏场景;方法:-(BOOL)isSpiderExist
App:com.alphaweb.fairyfail;类:IBBearBomb;方法:-(BOOL)isBomb
App:com.intsig.CamScannerHDPro;类:CSDataCenter;方法:+(bool)isPremiumAccount
App:com.intsig.CamScannerHDPro;类:CSLoggedinViewController;方法:-(bool)isPremiumAccount
App:com.intsig.CamScannerHDPro;类:ENSession;方法:-(bool)isPremiumUser
App:com.intsig.CamScannerHDPro;类:CSSettings;方法:+(bool)isPremiumFeatureAvailable
App:com.intsig.CamScannerHDPro;类:CSStoreManager;方法:-(int)faxBalance
App:com.intsig.CamScannerHDPro;类:CSStoreManager;方法:-(void)setFaxBalance:(int)
App:com.intsig.CamScannerHDPro;类:CSStoreManager;方法:-(bool)canSendFax
App:com.intsig.CamScannerHDPro;类:CSStoreManager;方法:-(void)setCanSendFax:(bool)
App:com.intsig.CamScannerHDPro;类:CSHDAppDelegate;方法:-(void)collectInfos

使用支持XPath的现代XML库,这要容易得多;因此,我在下面使用

全部输出为:

App:com.apprizon.follow4followapp;类:IBINappurchasesManager;方法:-(bool)isPremium
App:com.apprizon.follow4followapp;类:IBRedeemCodeView;方法:-(无符号长-长)奖励
App:com.apprizon.follow4followapp;类:IBGetFollowersGoldenFollowersCell;方法:-(void)setFreeFollowers:(long-long)
App:com.apprizon.follow4followapp;类:IBGetFollowersGoldenFollowersCell;方法:-(长-长)freeFollowers
App:com.apprizon.follow4followapp;类:IBSettings;方法:-(双精度)额外报酬ForPro
App:com.apprizon.follow4followapp;类:IBSettings;方法:-(void)setReferralMinReward:(long)
App:com.apprizon.follow4followapp;类:IBSettings;方法:-(长-长)referralMinReward
App:com.apprizon.follow4followapp;类:IBSettings;方法:-(void)setRewardForSecondaryAccount:(long)
App:com.apprizon.follow4followapp;类:IBSettings;方法:-(l)
import xml.dom.minidom

xml = xml.dom.minidom.parse('my.plist')

Document = xml.getElementsByTagName('plist')



for key in Document:
    desc = key.getElementsByTagName('string')[5].firstChild.data
    desc1 = key.getElementsByTagName('string')[6].firstChild.data

print('Class: ', desc, 'Function: ', desc1)


desc = key.getElementsByTagName('string')[11].firstChild.data
desc1 = key.getElementsByTagName('string')[12].firstChild.data

print('Class: ', desc, 'Function: ', desc1)


desc = key.getElementsByTagName('string')[17].firstChild.data
desc1 = key.getElementsByTagName('string')[18].firstChild.data

print('Class: ', desc, 'Function: ', desc1)

desc = key.getElementsByTagName('string')[23].firstChild.data
desc1 = key.getElementsByTagName('string')[24].firstChild.data

print('Class: ', desc, 'Function: ', desc1)


desc = key.getElementsByTagName('string')[29].firstChild.data
desc1 = key.getElementsByTagName('string')[30].firstChild.data

print('Class: ', desc, 'Function: ', desc1)
x = 5
for key in Document:
    desc = key.getElementsByTagName('string')[x].firstChild.data
    desc1 = key.getElementsByTagName('string')[x+1].firstChild.data
    print('Class: ', desc, 'Function: ', desc1)
    x += 5
import lxml.etree as etree
import sys

doc = etree.parse(open(sys.argv[1]))
for app_dict in doc.xpath('/plist/dict/array/dict'):
    appId = app_dict.xpath('./key[.="appIdentifier"]/following-sibling::string[1]/text()')[0]
    for method_dict in app_dict.xpath('.//dict[key="methodObjc"]/dict'):
        classId = method_dict.xpath('./key[.="className"]/following-sibling::string[1]/text()')[0]
        methodId = method_dict.xpath('./key[.="displayName"]/following-sibling::string[1]/text()')[0] 
        print 'App: %s; Class: %s; Method: %s' % (appId, classId, methodId)