ios xpath html 解析 lib包

时间:2016-05-13 06:00:22
【文件属性】:

文件名称:ios xpath html 解析 lib包

文件大小:9KB

文件格式:ZIP

更新时间:2016-05-13 06:00:22

ios xpath

可用 xpath ,html解析lib, 下面为方法,xpath路径可专门另研究。 NSData *htmlData = [[response dataUsingEncoding:NSUTF8StringEncoding] retain]; TFHpple *xpathParser = [[TFHpple alloc] initWithHTMLData:htmlData]; NSArray *arrayTitle = [xpathParser searchWithXPathQuery:@"//div[@class= 'item-box']/h3/a/attribute::title"]; NSArray *arrayPic = [xpathParser searchWithXPathQuery:@"//div[@class= 'item-box']/div[@class= 'pic']/p/a/span/img/attribute::src"]; NSArray *arrayUrl = [xpathParser searchWithXPathQuery:@"//div[@class= 'item-box']/h3/a/attribute::href"]; NSArray *arrayPrice = [xpathParser searchWithXPathQuery:@"//div[@class= 'col price']"];//价格 //此陣列為篩選結果 //TFHpple使用XPath來篩選,XPath介紹(W3C):http://www.w3school.com.cn/xpath/index.asp for(int i = 0; i < [arrayTitle count]; i++) { NSString *title = [[arrayTitle objectAtIndex:i] content]; NSString *pic = [[arrayPic objectAtIndex:i] content]; NSString *url = [[arrayUrl objectAtIndex:i] content]; NSString *price = [[arrayPrice objectAtIndex:i] content]; NSMutableDictionary* item_dic=[[NSMutableDictionary alloc] init]; [item_dic setValue:title forKey:ITEM_TITLE]; [item_dic setValue:pic forKey:ITEM_PIC]; [item_dic setValue:url forKey:ITEM_URL]; [item_dic setValue:price forKey:ITEM_PRICE]; [self.item_Array addObject:item_dic]; } [xpathParser release]; [htmlData release];


【文件预览】:
xpath
----XPathQuery.h(276B)
----TFHpple.h(2KB)
----TFHpple.m(3KB)
----XPathQuery.m(5KB)
----TFHppleElement.h(2KB)
----TFHppleElement.m(3KB)

网友评论

  • 挺好的,非常感谢!
  • 非常好,可以参考学习
  • 收获不少,谢谢了
  • 没太用明白,还在努力学习中
  • 不咋好,不过也有启发