NSString *str = @"斗罗大陆";
str = [str stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
NSString *urlStr = [NSString stringWithFormat:@"http://api.dushubus.com/api/search?count=20&page=1&name=%@&uuid=564060195937280&",str];
NSURL *url = [NSURL URLWithString:urlStr];
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url];
[NSURLConnection sendAsynchronousRequest:request queue:[NSOperationQueue mainQueue] completionHandler:^(NSURLResponse *response, NSData *data, NSError *connectionError) {
if (data) {
@autoreleasepool {
self.names = [NSMutableArray array];
self.authors = [NSMutableArray array];
NSDictionary *dic = [data objectFromJSONData];
NSArray *arr = [dic objectForKey:@"content"];
for (NSDictionary *contentDic in arr) {
[self.names addObject:[contentDic objectForKey:@"name"]];
[self.authors addObject:[contentDic objectForKey:@"author"]];
// NSLog(@"%@",[contentDic objectForKey:@"name"]);
}
NSString *author = [self.authors objectAtIndex:0];
NSString *name = [self.names objectAtIndex:0];
author = [author stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
name = [name stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
NSString *downInfo = [NSString stringWithFormat:@"http://api.dushubus.com/api/downInfo?author=%@&name=%@&uuid=564060195937280&",author,name];
NSURL *url1 = [NSURL URLWithString:downInfo];
NSMutableURLRequest *request1 = [NSMutableURLRequest requestWithURL:url1];
[NSURLConnection sendAsynchronousRequest:request1
queue:[NSOperationQueue mainQueue]
completionHandler:^(NSURLResponse *response, NSData *data, NSError *connectionError)
{
if (data) {
self.listUrls = [NSMutableArray array];
NSDictionary *dic = [data objectFromJSONData];
NSArray *arr = [dic objectForKey:@"content"];
for (NSDictionary *content in arr) {
[self.listUrls addObject:[content objectForKey:@"listUrl"]];
}
NSLog(@"%@",self.listUrls);
NSString *urlName = [self.listUrls objectAtIndex:0];
NSString *newUrlName = [urlName stringByReplacingOccurrencesOfString:@":" withString:@"%3A"];
NSString *newUrlName1 = [newUrlName stringByReplacingOccurrencesOfString:@"/" withString:@"%2F"];
NSString *renew = [NSString stringWithFormat:@"http://api.dushubus.com/api/renew?listUrl=%@&uuid=564060195937280",newUrlName1];
NSURL *url = [NSURL URLWithString:renew];
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url];
[NSURLConnection sendAsynchronousRequest:request
queue:[NSOperationQueue mainQueue]
completionHandler:^(NSURLResponse *response, NSData *data, NSError *connectionError)
{
if (data) {
self.urls = [NSMutableArray array];
NSDictionary *dic = [data objectFromJSONData];
NSDictionary *content = [dic objectForKey:@"content"];
NSMutableArray *chapters = [content objectForKey:@"chapters"];
for (NSDictionary *desDic in chapters) {
NSLog(@"%@",[desDic objectForKey:@"title"]);
[self.urls addObject:[desDic objectForKey:@"url"]];
}
NSString *urlName = [self.urls objectAtIndex:0];
NSString *newUrlName = [urlName stringByReplacingOccurrencesOfString:@":" withString:@"%3A"];
NSString *newUrlName1 = [newUrlName stringByReplacingOccurrencesOfString:@"/" withString:@"%2F"];
NSString *contData = [NSString stringWithFormat:@"http://novel.mse.sogou.com/http_interface/getContData.php?url=%@",newUrlName1];
NSLog(@"contData = %@",contData);
NSURL *url = [NSURL URLWithString:contData];
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url];
[NSURLConnection sendAsynchronousRequest:request
queue:[NSOperationQueue mainQueue]
completionHandler:^(NSURLResponse *response, NSData *data, NSError *connectionError)
{
if (data) {
NSDictionary *dic = [data objectFromJSONData];
NSMutableArray *content = [dic objectForKey:@"content"];
for (NSDictionary *blockDic in content) {
NSString *blockStr = [blockDic objectForKey:@"block"];
NSLog(@"%@",blockStr);
}
}else {
NSLog(@"第三层为空");
}
}];
}else {
NSLog(@"第二层为空");
}
}];
}else {
NSLog(@"为空");
}
}];
}
}else {
NSLog(@"@为空");
}
}];