2011-08-30 71 views
0

值這是一個後續我剛纔的問題:Extracting an href's text from an html document提取從HTML HREF的屬性

我怎樣才能在seekVideo(number)多少?例如:

<a href="#" class="transcriptLink" onclick="seekVideo(2000); return false;" 

我想要「2000」。

我曾嘗試:

NSArray *elements = [xpathParser search:@"//div[@id='transcriptText']/div/p/number(substring-before(substring-after(@onclick, '('), ')'))"]; 

但是,這是不對的。我怎樣才能做到這一點?

如果有人可以使用Kirill Polishchuk在此Web提供的代碼框架(https://stackoverflow.com/questions/6723244/iphone-how-to-select-this-label),那就太棒了。

+0

可能重複? ](http://stackoverflow.com/questions/7231132/iphone-how-to-get-this-label) – Mat

回答

0

您可以使用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測試[56342:707] seekVideo:2000 [iphone,如何讓這個標籤的