| 注册
请输入搜索内容

热门搜索

Java Linux MySQL PHP JavaScript Hibernate jQuery Nginx
openkk
12年前发布

Objective-C编写的简易 HTML 解析器:Objective-C-HMTL-Parser

Objective-C-HMTL-Parser 是一个用 ObjectiveC 编写的简易 HTML 解析器。

示例代码:

NSError *error = nil;  NSString *html =      @"<ul>"          "<li><input type='image' name='input1' value='string1value' /></li>"          "<li><input type='image' name='input2' value='string2value' /></li>"      "</ul>"      "<span class='spantext'><b>Hello World 1</b></span>"      "<span class='spantext'><b>Hello World 2</b></span>";  HTMLParser *parser = [[HTMLParser alloc] initWithString:html error:&error];    if (error) {      NSLog(@"Error: %@", error);      return;  }    HTMLNode *bodyNode = [parser body];    NSArray *inputNodes = [bodyNode findChildTags:@"input"];    for (HTMLNode *inputNode in inputNodes) {      if ([[inputNode getAttributeNamed:@"name"] isEqualToString:@"input2"]) {          NSLog(@"%@", [inputNode getAttributeNamed:@"value"]); //Answer to first question      }  }    NSArray *spanNodes = [bodyNode findChildTags:@"span"];    for (HTMLNode *spanNode in spanNodes) {      if ([[spanNode getAttributeNamed:@"class"] isEqualToString:@"spantext"]) {          NSLog(@"%@", [spanNode rawContents]); //Answer to second question      }  }    [parser release];

项目主页:http://www.open-open.com/lib/view/home/1344848562522

 本文由用户 openkk 自行上传分享,仅供网友学习交流。所有权归原作者,若您的权利被侵害,请联系管理员。
 转载本站原创文章,请注明出处,并保留原始链接、图片水印。
 本站是一个以用户分享为主的开源技术平台,欢迎各类分享!
 本文地址:https://www.open-open.com/lib/view/open1344848562522.html
HTML操作类库 Objective-C