NSString *str = @"<'html><'img src= 'pic.jpg'/><'/html>";
Maintenant, je veux obtenir pic.jpg
,Comment analyser le code html! Je veux obtenir un tag dans le code html pour iPhone
Comment puis-je rechercher la chaîne?
NSString *str = @"<'html><'img src= 'pic.jpg'/><'/html>";
Maintenant, je veux obtenir pic.jpg
,Comment analyser le code html! Je veux obtenir un tag dans le code html pour iPhone
Comment puis-je rechercher la chaîne?
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.
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
ok .. merci .. je juste comment le faire – rbbtsn0w