2011-08-02 5 views

Répondre

2

Le code dépend de libxml2 et est fondamentalement un wrapper mince qui fournit une interface plus pratique pour l'analyse de html avec Objective C. Cela a seulement été testé sur iOS 3.1.3 & 3.2, si vous utilisez OSX vous êtes probablement mieux d'enquêter en utilisant WebKit pour manipuler votre DOM. Le code suivant peut vous aider.

//Example to download google's source and print out the urls of all the images 
NSError * error = nil; 
HTMLParser * parser = [[HTMLParser alloc] initWithContentsOfURL:[NSURL URLWithString:@"http://www.google.com"] error:&error]; 
if (error) { 
    NSLog(@"Error: %@", error); 
    return; 
} 

HTMLNode * bodyNode = [parser body]; //Find the body tag 
NSArray * imageNodes = [bodyNode findChildTags:@"img"]; //Get all the <img alt="" /> 
for (HTMLNode * imageNode in imageNodes) { //Loop through all the tags 
    NSLog(@"Found image with src: %@", [imageNode getAttributeNamed:@"src"]); //Echo the src="" 
} 

[parser release]; 

This libxml wrapper for Objective C peut également être utile.

+0

wow .. Merci pour votre aide, HonestSuccess. vous pouvez m'aider agin? si i n'a pas de structure libxml2. comment puis-je le faire et obtenir les résultats? – rbbtsn0w

+0

ok .. merci .. je juste comment le faire – rbbtsn0w

Questions connexes