iPhone:使用hpple解析html,Xpath导航



hpple采用了 Xpath 实现对html的导航和解析,该lib使用简单,但需要对项目做一些设置:


链接libxml2库:


1、打开项目的TARGETS,选择ALL标签(如图):



2、在搜索栏搜索“Header Search Path”,添加属性:

“${SDKROOT}/usr/include/libxml2”



3、和第二步一样,在 “Other Linker Flag”下添加:

“-lxml2”



Git链接:

git clone git://github.com/topfunky/hpple.git


导入相应文件:

TFHpple.h
TFHpple.m
TFHppleElement.h
TFHppleElement.m
XPathQuery.h
XPathQuery.m


用法:

 // Don't forget
 // #import "TFHpple.h"
 NSData *htmlData = [[NSString stringWithContentsOfURL:[NSURL URLWithString: @"http://www.objectgraph.com/contact.html"]] dataUsingEncoding:NSUTF8StringEncoding];
 TFHpple *xpathParser = [[[TFHpple alloc] initWithHTMLData:htmlData] autorelease];
 NSArray *elements  = [xpathParser search:@"//h3"]; // get the page title - this is xpath notation
 TFHppleElement *element = [elements objectAtIndex:0];
 NSString *myTitle = [element content];
 NSLog(myTitle);


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值