SIHTMLParser 1.1

SIHTMLParser 1.1

TestsTested
LangLanguage Obj-CObjective C
License MIT
ReleasedLast Release Aug 2017

Maintained by Silence0201.



  • By
  • Silence

HTMLParser

HTMLParser:一个简单的Html解析器Reference StackOverflow

使用说明

导入

手工导入

  1. 将项目下HTMLParser导入项目中,
  2. 点击Bulid Phases->Link FrameWork and Libraries,添加libxml2.tbdlibxml2.dylib
  3. 在项目设置中Bulid Setting->header search paths,添加$(SDKROOT)/usr/include/libxml2

Pod安装

pod 'SIHTMLParser', '~> 1.0'

使用

  1. 导入头文件

    #import "HTMLParser.h"
  2. 初始化Parser

    NSError *error = nil;
    NSString *path = [[NSBundle mainBundle]pathForResource:@"test" ofType:@"html"] ;
    NSData *htmlData = [NSData dataWithContentsOfFile:path] ;
    HTMLParser *parser = [[HTMLParser alloc] initWithData:htmlData error:&error] ;
  3. 查询节点信息

    HTMLNode *body = [parser body] ;
    
    NSArray *array = [body findChildrenOfClass:@"cell item"] ;
    NSArray *a = [array.firstObject findChildTags:@"a"] ;
    for (HTMLNode *node in a){
        NSLog(@"%@",[node contents]) ;
    }
  4. 更多使用请查看头文件说明

HTMLParser

HTMLParser is available under the MIT license. See the LICENSE file for more info.