hpple 0.2.0

hpple 0.2.0

测试已测试
语言语言 Obj-CObjective C
许可 MIT
发布最新发布2014年12月

由 . 维护



hpple 0.2.0

  • Geoffrey Grosenbach

描述

Hpple:XPathQuery 库上的一种优美的 Objective-C 包装,用于解析 HTML。

受 why the lucky stiff 的 Hpricot 启发。

致谢

Hpple 由 Geoffrey Grosenbach 创建,Topfunky CorporationPeepCode Screencasts

贡献者

特性

  • 通过 XPath 搜索简单(CSS 选择器即将推出)
  • 解析 HTML(XML 即将推出)
  • 轻松访问标签内容、名称和属性。

安装

  • 打开您的 XCode 项目和 Hpple 项目。
  • 将 "Hpple" 文件夹拖到您的项目中。
  • 将 libxml2.2.dylib 框架添加到您的项目中,并按照 Cocoa with Love 中所述添加搜索路径

更多文档和简短视频教程即将推出...

使用方法

请参阅 Hpple 项目中的 TFHppleHTMLTest.m 以获取示例。

#import "TFHpple.h"

NSData  * data      = [NSData dataWithContentsOfFile:@"index.html"];

TFHpple * doc       = [[TFHpple alloc] initWithHTMLData:data];
NSArray * elements  = [doc search:@"//a[@class='sponsor']"];

TFHppleElement * element = [elements objectAtIndex:0];
[e text];                       // The text inside the HTML element (the content of the first text node)
[e tagName];                    // "a"
[e attributes];                 // NSDictionary of href, class, id, etc.
[e objectForKey:@"href"];       // Easy access to single attribute
[e firstChildWithTagName:@"b"]; // The first "b" child node

待办事项

  • 内部错误捕获和消息
  • 除了 XPath 之外,还有 CSS3 选择器