2017-05-20 2 views
0

Das ist mein plist/xml (Ich habe es ein wenig verkürzt, aber es ist immer noch riesig, so dass ich es als Link: https://ghostbin.com/paste/rbu9tPython - Gewinnen Informationen aus plist/xml

Was ich tun möchte, ist extrahieren Sie die Felder wie:

appIdentifier
classname
Funktion < --- Funktion = Die Linie nach "displayname"

Was ich jetzt habe. http://i.imgur.com/X8wlHod.gif

Aber wenn ich das Muster fortsetze, wird es falsche Sachen extrahieren.

Ich möchte in der Lage sein, alle Funktionen und Klassennamen für jede App zu extarct, bevor ich mit dem nächsten gehe.

Und wenn das nicht möglich ist, dann möchte ich in der Lage sein, alle Klassen und Funktionen zu extrahieren, aber mit einem plist/xml, das nur die Informationen einer App hat.

OLD QUESTION: I'm coding a program, but as you can see, I'm doing +6 then +1, then +6, then +1. Is there a way to automate this (some program or site) or some code to help me? Cheers!

Mein Code: (* Anmerkung:. Die Anzahl Muster wirklich nicht so viel helfen, wie ich dachte, da jede Anwendung unterschiedliche Mengen von Klassen und Funktionen haben kann

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) 

Sorry, wenn die Post ist nicht sehr detailliert oder erklärt, wenn Sie Fragen haben, ich sie so gut beantworten werde, wie ich kann!

+0

Ihre Einbuchtung wenig Sinn macht. Bitte repariere es. –

+0

BTW, ich wäre sehr überrascht, wenn Sie tatsächlich einen Grund hätten, hier eine numerische Indexierung vorzunehmen - wenn wir das tatsächliche Format Ihrer XML - Eingabe erhalten würden, würde ich wetten, dass wir eine Antwort liefern könnten, die nicht die Kenntnis der Relativ Offset überhaupt, und würde immer noch funktionieren, wenn das in der Zukunft geändert wird. –

+0

@CharlesDuffy Ich hoffe es! Beitrag wird jetzt aktualisiert! :) – CandyGum

Antwort

0

Dies ist viel einfacher mit einer modernen XML-Bibliothek, die XPath unterstützt; Daher verwende ich lxml unten.

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) 

Volle Leistung ist:

App: com.apprizon.follow4followapp; Class: IBInAppPurchasesManager; Method: -(bool) isPremium 
App: com.apprizon.follow4followapp; Class: IBRedeemCodeView; Method: -(unsigned long long) reward 
App: com.apprizon.follow4followapp; Class: IBGetFollowersGoldenFollowersCell; Method: -(void) setFreeFollowers:(long long) 
App: com.apprizon.follow4followapp; Class: IBGetFollowersGoldenFollowersCell; Method: -(long long) freeFollowers 
App: com.apprizon.follow4followapp; Class: IBSettings; Method: -(double) extraRewardForPro 
App: com.apprizon.follow4followapp; Class: IBSettings; Method: -(void) setReferralMinReward:(long long) 
App: com.apprizon.follow4followapp; Class: IBSettings; Method: -(long long) referralMinReward 
App: com.apprizon.follow4followapp; Class: IBSettings; Method: -(void) setRewardForSecondaryAccount:(long long) 
App: com.apprizon.follow4followapp; Class: IBSettings; Method: -(long long) rewardForSecondaryAccount 
App: com.apprizon.follow4followapp; Class: IBSettings; Method: -(void) setExtraRewardForPro:(double) 
App: com.apprizon.follow4followapp; Class: IBMe; Method: -(unsigned long long) availableSpins 
App: com.apprizon.follow4followapp; Class: IBMe; Method: -(bool) canRedeemCode 
App: com.apprizon.follow4followapp; Class: IBMe; Method: -(void) setCanRedeemCode:(bool) 
App: com.apprizon.follow4followapp; Class: IBSettings; Method: -(bool) wofFreeSpinsEnabled 
App: com.apprizon.follow4followapp; Class: IBSettings; Method: -(void) setWofFreeSpinsEnabled:(bool) 
App: com.apprizon.follow4followapp; Class: IBWheelOfFortuneView; Method: -(long long) numberOfFreeSpins 
App: com.apprizon.follow4followapp; Class: IBWheelOfFortuneView; Method: -(void) setNumberOfFreeSpins:(long long) 
App: com.apprizon.follow4followapp; Class: IBWheelOfFortunePrizeView; Method: -(bool) freeSpinAvailable 
App: com.apprizon.follow4followapp; Class: IBWheelOfFortunePrizeView; Method: -(void) setFreeSpinAvailable:(bool) 
App: com.apprizon.follow4followapp; Class: IBWheelOfFortuneManager; Method: -(bool) freeSpinAvailable 
App: com.apprizon.follow4followapp; Class: IBMiniGame; Method: -(void) setPrize:(id) 
App: com.apprizon.follow4followapp; Class: IBMiniGame; Method: -(id) prize 
App: com.apprizon.follow4followapp; Class: IBSettings; Method: -(unsigned long long) maxEnergyDefault 
App: com.apprizon.follow4followapp; Class: IBSettings; Method: -(void) setMaxEnergyDefault:(unsigned long long) 
App: com.betternet; Class: BetternetUser; Method: -(bool) isPremium 
App: com.betternet; Class: BetternetUser; Method: -(void) setIsPremium:(bool) 
App: com.betternet; Class: BetternetUser; Method: -(bool) allowedPremium 
App: com.betternet; Class: GADDevice; Method: -(bool) jailbroken 
App: com.betternet; Class: FlurryUtil; Method: +(BOOL) deviceIsJailbroken 
App: co.allconnected.vpnmaster; Class: FlurryUtil; Method: +(BOOL) deviceIsJailbroken 
App: com.anchorfree.hss; Class: ZDKUser; Method: -(bool) isAgent 
App: com.anchorfree.hss; Class: AFUserAccount; Method: -(void) setAuto_renew:(bool) 
App: com.anchorfree.hss; Class: AFUserAccount; Method: -(bool) auto_renew 
App: com.anchorfree.hss; Class: AFUserAccount; Method: -(void) setIsValid:(bool) 
App: com.apprizon.follow4followapp; Class: IBInAppPurchasesManager; Method: -(bool) isPremium 
App: com.alphaweb.fairyfail; Class: IBBearGood; Method: -(float) speed 
App: com.alphaweb.fairyfail; Class: GameScene; Method: -(int) totalNumberOfStars 
App: com.alphaweb.fairyfail; Class: BalloonSprite; Method: -(float) speed 
App: com.alphaweb.fairyfail; Class: GameScene; Method: -(BOOL) rateMenuShouldBeDisplayed 
App: com.alphaweb.fairyfail; Class: GameScene; Method: -(BOOL) isSpiderExist 
App: com.alphaweb.fairyfail; Class: IBBearBomb; Method: -(BOOL) isBomb 
App: com.intsig.CamScannerHDPro; Class: CSDataCenter; Method: +(bool) isPremiumAccount 
App: com.intsig.CamScannerHDPro; Class: CSLoggedinViewController; Method: -(bool) isPremiumAccount 
App: com.intsig.CamScannerHDPro; Class: ENSession; Method: -(bool) isPremiumUser 
App: com.intsig.CamScannerHDPro; Class: CSSettings; Method: +(bool) isPremiumFeatureAvailable 
App: com.intsig.CamScannerHDPro; Class: CSStoreManager; Method: -(int) faxBalance 
App: com.intsig.CamScannerHDPro; Class: CSStoreManager; Method: -(void) setFaxBalance:(int) 
App: com.intsig.CamScannerHDPro; Class: CSStoreManager; Method: -(bool) canSendFax 
App: com.intsig.CamScannerHDPro; Class: CSStoreManager; Method: -(void) setCanSendFax:(bool) 
App: com.intsig.CamScannerHDPro; Class: CSHDAppDelegate; Method: -(void) collectInfos 
+0

ich diesen Fehler: doc = lxml. etree.parse (open (sys.argv [1])) NameError: name 'lxml' ist nicht definiert ' – CandyGum

+0

Hoppla - sorry, nur 'etree.parse', da der Import' astree' hat. –

+0

Das hat es behoben :) Jetzt habe ich 'doc = etree.parse (open (sys.argv [1])) IndexError: Listenindex außerhalb des Bereichs '' Auch, wo gebe ich meinen Dateinamen ein? – CandyGum

1
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 

können Sie versuchen, über Code-Schnipsel, hoffe, das hilft

+0

wenn hilfreich, fügen Sie es als die richtige Antwort akzeptieren – pramod

Verwandte Themen