ios hpple解析html demo
来源:互联网 发布:说明书排版设计软件 编辑:程序博客网 时间:2024/05/17 02:46
// rootViewController.m
// QduniversityJobhelper
//
// Created by niuxinghua on 14-12-17.
// Copyright (c) 2014年 niuxinghua. All rights reserved.
//
#import "rootViewController.h"
#import "Config.h"
#import "AFNetworking.h"
#import "TFHpple.h"
#import "TFHppleElement.h"
#import "XPathQuery.h"
#import "TFHpple.h"
#import "JobBean.h"
#import "myCell.h"
@interface rootViewController ()
@end
@implementation rootViewController
- (instancetype)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad
{
[superviewDidLoad];
CGFloat width=mainWidth;
CGFloat height=mainHeight;
_datalist=[[NSMutableArrayalloc]init];
// Do any additional setup after loading the view.
_button=[UIButtonbuttonWithType:UIButtonTypeRoundedRect];
_button.frame=CGRectMake(width/2-40,80,80, 40);
[_buttonsetTitle:@"load"forState:UIControlStateNormal];
[_buttonaddTarget:selfaction:@selector(load)forControlEvents:UIControlEventTouchUpInside];
_text=[[UITextFieldalloc]initWithFrame:CGRectMake(0,120, width, height-120)];
_table=[[UITableViewalloc]initWithFrame:CGRectMake(0,120, width, height-120)style:UITableViewStylePlain];
_table.delegate=self;
_table.dataSource=self;
[self.view addSubview:_button];
[self.view addSubview:_table];
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView
numberOfRowsInSection:(NSInteger)section{
return [_datalistcount];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *reuseIdetify =@"SvTableViewCell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:reuseIdetify];
if (!cell) {
cell = [[UITableViewCellalloc]initWithStyle:UITableViewCellStyleDefaultreuseIdentifier:reuseIdetify];
cell.accessoryType =UITableViewCellAccessoryDisclosureIndicator;
cell.showsReorderControl =YES;
}
NSInteger row = [indexPath row];
JobBean* bean=[_datalistobjectAtIndex:row];
cell.textLabel.backgroundColor = [UIColorclearColor];
cell.textLabel.text = bean.jobTitle;
// JobBean* bean=[_datalist objectAtIndex:row];
return cell;
}
-(void)load{
NSString *urlstring=@"http://career.ouc.edu.cn/recruitment/campus/";//此处网址不对,只是示意可以生成一个动态的urlstring
NSURL *url = [NSURLURLWithString:urlstring];
NSData *data = [NSDatadataWithContentsOfURL:url];
TFHpple * doc = [[TFHpplealloc]initWithHTMLData:data];
NSArray * elements = [doc searchWithXPathQuery:@"//a"];
for (int i=10; i<[elementscount]-27; i++) {
TFHppleElement * element = [elementsobjectAtIndex:i];
NSString *links=[element raw];
NSArray* href=[linkscomponentsSeparatedByString:@" "];
NSString *link=[href objectAtIndex:1];
NSString *link1=[link substringFromIndex:6];
int length=[link1 length]-1;
NSString *reallink=[link1 substringToIndex:length];
NSLog(@"%@",[elementtext]);
NSLog(@"%@",reallink);
JobBean *bean=[[JobBeanalloc]init];
bean.jobTitle=[element text];
bean.jobDetilurl=reallink;
[_datalist addObject:bean];
}
[_tablereloadData];
}
-(NSString *)urlString:(NSString *)value{
NSURL *url = [NSURLURLWithString:value];
NSData *data = [NSDatadataWithContentsOfURL:url];
//解决中文乱码,用GBK
NSStringEncoding enc =CFStringConvertEncodingToNSStringEncoding(kCFStringEncodingGB_18030_2000);
NSString *retStr = [[NSStringalloc]initWithData:data encoding:enc];
return retStr;
}
- (void)didReceiveMemoryWarning
{
[superdidReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
/*
#pragma mark - Navigation
// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
// Get the new view controller using [segue destinationViewController].
// Pass the selected object to the new view controller.
}
*/
@end
- ios hpple解析html demo
- iPhone:使用hpple解析html,Xpath导航
- iPhone:使用hpple解析html,Xpath导航
- 使用libxml解析HTML -- Hpple
- 使用Objective-C HPPLE库解析HTML和XML
- OC解析html的类库Hpple的一些方法
- iOS: 用libxml2 and hpple来做html parser
- iOS: 用libxml2 and hpple来做html parser
- iOS: 用libxml2 and hpple来做html parser
- 如何使用Hpple解析HTML,以及获取网站上的所有超链接
- IOS文件解析 之第三方框架Hpple的简单使用
- Jsoup解析HTML Demo
- ios hpple通过xpath抓取数据。
- iOS CLGeocoder(地图解析)~demo
- iOS 架构模式Demo解析
- iOS解析HTML
- iOS解析HTML .
- iOS解析HTML
- 由Maximum Gap,谈桶排序,基数排序和计数排序
- Unity3D学习基本知识
- Reverse Integer(leetcode)
- Python抓取Excel表数据至MySQL表
- 用perl找到图片信息
- ios hpple解析html demo
- C#读写txt文件
- 第一次只出现一次的字符
- 基于wsdl2java访问外来service服务
- NSInteger转Byte字节
- 手斧Linux – 从LFS到Funtoo (2)
- hdu 1159 Common Subsequence (dp求LCS)
- Spring 环境搭建与IoC和AOP
- 联发科技笔试题