【问题标题】:Extracting a value from an html href's attribute从 html href 的属性中提取值
【发布时间】:2011-08-30 09:03:19
【问题描述】:

这是我上一个问题的后续:Extracting an href's text from an html document

如何获取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 在本网站提供的代码框架(https://stackoverflow.com/questions/6723244/iphone-how-to-select-this-label),那就太好了。

【问题讨论】:

标签: iphone html xml


【解决方案1】:

你可以使用 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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-06-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-03-02
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多