本文介绍了iPhone,如何获得此标签?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

<div>
  <p>
    <a href="#" class="transcriptLink" onclick="seekVideo(0); return false;">A few years ago,</a>
    <a href="#" class="transcriptLink" onclick="seekVideo(2000); return false;">I felt like I was stuck in a rut,</a>
    <a href="#" class="transcriptLink" onclick="seekVideo(5000); return false;">so I decided to follow in the footsteps</a>
    <a href="#" class="transcriptLink" onclick="seekVideo(7000); return false;">of the great American philosopher, Morgan Spurlock,</a>
    <a href="#" class="transcriptLink" onclick="seekVideo(10000); return false;">and try something new for 30 days.</a>
  </p>
</div>

这是网络代码的一部分.

this is a part of web code .

我想知道如何在label中获取文本.例如:几年前",

i want to know how to get the text in label . such as:"A few years ago,"

我可以在< a>文本</a>",

但是我不知道如何在""标签中获得几年前"的标签.< a href =#" class ="transcriptLink" onclick ="seekVideo(0);return false;>几年前,</a>"

but i do not know how to get "A few years ago," in label of "<a href="#" class="transcriptLink" onclick="seekVideo(0); return false;">A few years ago,</a> "

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

只有 onclick ="seekVideo(....);

/div/p/a [substring-before(substring-after(@onclick,'('),')')='0']/text()

可以获得类似几年前"的文本;

但是现在我想在 seekVideo(number)中获取数字?????

but now i want to get the number in seekVideo(number)????

/div/p/a [number(substring-before(substring-after(@onclick,'('),')'))]

不对!!!

例如:< a href =#" class ="transcriptLink" onclick ="seekVideo(2000);返回false;">

我想得到"2000",怎么办?

i want to get "2000", how to do?

示例项目或代码更好,谢谢

sample project or code is better, thanks

推荐答案

如果它是有效的XML(从示例中向我们展示了它是有效的XML),则可以使用NSXMLParser进行解析.

If its a valid XML (from the example you showed us it is valid XML) you can Parse using NSXMLParser.

- (void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string{
    if(!currentString){
        currentString = [[NSMutableString alloc] init];
    }
    [currentString appendString:string];    
}

- (void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName {
    if([elementName isEqualToString:@"a"]){
        NSLog(@"Text betweeen \"a\" tag %@",currentString);
    }
    [currentString release],currentString =nil;
}

要从seekVideo(0)中获取0,请使用

To get 0 from seekVideo(0), use

- (void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qualifiedName attributes:(NSDictionary *)attributeDict{
    if([elementName isEqualToString:@"a"]){
        NSString* onClickAttribString = [attributeDict objectForKey:@"onclick"];
        NSLog(@"OnClick Attrib: %@",onClickAttribString);
        // seekVideo(0); return false; 
        NSArray* arrayList = [onClickAttribString componentsSeparatedByString:@" "]; // gives array of string seperated by space
        NSLog(@"seekvideo %@",[arrayList objectAtIndex:0]);
        //Process seekvideo(0); to get number... use NSScanner
        NSString* seekVideoString = [arrayList objectAtIndex:0];
        NSString* numberString = [seekVideoString stringByTrimmingCharactersInSet:[[NSCharacterSet decimalDigitCharacterSet] invertedSet]];
        NSLog(@"Number : %@",numberString);
        // if you want numberString converted to integer then [numberString intValue]
    }
}

这篇关于iPhone,如何获得此标签?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-14 03:54