NSError *error = nil;
NSError *error1 = nil;
NSURLRequest *request = [NSURLRequest requestWithURL:htmlurl];
//将请求的url数据放到NSData对象中
NSData *response = [NSURLConnection sendSynchronousRequest:request returningResponse:nil error:&error];
NSString *str = [[NSString alloc] initWithData:response encoding:NSUTF8StringEncoding];
//IOS5自带解析类NSJSONSerialization从response中解析出数据放到字典中
if (error) {
}
if (error1) {
}
HTMLNode *bodyNode = [parser body];
NSArray *spanNodes = [bodyNode findChildTags:@"table"];
HTMLNode *bodyNode1 = [spanNodes lastObject];
NSMutableArray *allDataarr = [[NSMutableArray alloc] init];
NSArray *spanNodes1 = [bodyNode1 findChildTags:@"tr"];
NSString *str1 = [[NSString alloc] init];
NSString *strout = [[NSString alloc] init];
for (HTMLNode *bodeNode2 in spanNodes1) {
NSArray *spanNodes2 = [bodeNode2 findChildTags:@"td"];
for (HTMLNode *bodeNode3 in spanNodes2) {
str1 = [bodeNode3 contents];//取得 包含在bodeNode3节点中的内容;
if (str1==nil) {
str1 = @"";
}
NSString *str2 = [[NSString alloc] init];
NSArray *spanNodes3 = [bodeNode3 findChildTags:@"a"];
if ([spanNodes3 count]>0) {
for (HTMLNode *bodeNode4 in spanNodes3) {
str2 = [bodeNode4 contents];
}
strout = [str1 stringByAppendingString:str2];
}
else{
strout = str1;
}
[allDataarr addObject:strout];
}
}