Extracting a value from an html href's attribute
This is a followup to my previous question: Extracting an href's text from an html document
How can I get the number in seekVideo(number)
? For example:
<a href="#" class="transcriptLink" onclick="seekVideo(2000); return false;"
I want to get "2000".
I have tried:
NSArray *elements = [xpathParser search:@"//div[@id='transcriptText']/div/p/number(substring-before(substring-after(@onclick, '('), ')'))"];
But that's not right. How can I do this?
If someone can you use the code framework that Kirill Polishchuk provided in this web(https开发者_如何学Go://stackoverflow.com/questions/6723244/iphone-how-to-select-this-label), it would be great.
You can use NSScanner:
int seekVideo = 0;
NSString *testString = @"<a href=\"#\" class=\"transcriptLink\" onclick=\"seekVideo(2000); return false;\"";
NSScanner *scanner = [NSScanner scannerWithString:testString];
[scanner scanUpToString:@"seekVideo(" intoString:nil];
[scanner scanString:@"seekVideo(" intoString:nil];
[scanner scanInt:&seekVideo];
NSLog(@"seekVideo: %d", seekVideo);
2011-08-30 07:47:11.504 Test[56342:707] seekVideo: 2000
精彩评论