简体   繁体   English

从html href属性中提取值

[英]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 这是我之前的问题的跟进: 从html文档中提取href的文本

How can I get the number in seekVideo(number) ? 如何获取seekVideo(number) For example: 例如:

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

I want to get "2000". 我想得到“ 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://stackoverflow.com/questions/6723244/iphone-how-to-select-this-label), it would be great. 如果有人可以使用此网页上的Kirill Polishchuk提供的代码框架(https://stackoverflow.com/questions/6723244/iphone-how-to-select-this-label),那就太好了。

You can use NSScanner: 您可以使用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 2011-08-30 07:47:11.504测试[56342:707] seekVideo:2000

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM