s'il vous plaît utiliser hpple (XPath), Ceci est un suivi à ma question précédente:Comment obtenir des éléments de html, xml par hpple (xpath)?
http://stackoverflow.com/questions/6723244/iphone-how-to-select-this-label
Comment puis-je obtenir le numéro dans seekVideo(number)
? Par exemple:
<a href="#" class="transcriptLink" onclick="seekVideo(2000); return false;"
Je veux obtenir "2000".
J'ai essayé:
NSArray *elements = [xpathParser search:@"//div[@id='transcriptText']/div/p/number(substring-before(substring-after(@onclick, '('), ')'))"];
Mais ce qui ne va pas. Comment devrais-je faire cela?
Si quelqu'un peut utiliser le framework de code nommé hpple (xpath), ce serait génial.
Ceci est mon code pour obtenir du texte, maintenant comment changer pour obtenir le numéro ?????
#define WebSite @"http://www.ted.com/talks/matt_cutts_try_something_new_for_30_days.html"
- (void)setLoadData
{
NSData *siteData = [[NSData alloc] initWithContentsOfURL:[NSURL URLWithString:WebSite]];
TFHpple *xpathParser = [[TFHpple alloc] initWithHTMLData:siteData];
NSArray *elements = [xpathParser search:@"//div[@id='transcriptText']/div/p/a[number(substring-before(substring-after(@onclick, '('), ')')) >2000]/text()"];
NSMutableArray *arr = [[NSMutableArray alloc] init];
for (TFHppleElement *element in elements)
{
NSString *strs = [element content];
NSLog(@"cc: %@", strs);
[arr addObject:strs];
NSLog(@"arr: %@", arr);
}
self.listData = arr;
[arr release];
[xpathParser release];
}
Bonne question, +1. Voir ma réponse pour l'explication du problème et pour une expression XPath correcte qui évalue le nombre voulu. –