网络解析html

阅读: 评论:0

网络解析html

网络解析html

  // Request: My API (=1&ver=iphone&app_ver=8)NSURL *URL = [NSURL URLWithString:@"=1&ver=iphone&app_ver=8"];NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:URL];request.HTTPMethod = @"GET";request.timeoutInterval = 30;// Request OperationAFHTTPRequestOperation *operation = [[AFHTTPRequestOperation alloc] initWithRequest:request];sponseSerializer = [AFJSONResponseSerializer serializer];//自动对返回的数据进行json解析// Progress & Completion blocks[operation setDownloadProgressBlock:^(NSUInteger bytesRead, long long totalBytesRead, long long totalBytesExpectedToRead) {//NSLog(@"Received %lld of %lld bytes", totalBytesRead, totalBytesExpectedToRead);}];[operation setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation, id responseObject) {NSLog(@"Success: Status Code %ld", (sponse.statusCode);NSLog(@"%@", responseObject);//数据处理NSString *sourceString = [[responseObject firstObject] objectForKey:@"source"];NSString *titleString = [[responseObject firstObject] objectForKey:@"title"];NSString *pubdateString = [[responseObject firstObject] objectForKey:@"pubdate"];NSString *authorString = [[responseObject firstObject] objectForKey:@"author"];NSString *contentString = [[responseObject firstObject] objectForKey:@"content"];NSArray *newsArray = [[responseObject firstObject] objectForKey:@"news"];NSMutableString *newsString = [[NSMutableString alloc] initWithString:@"<ul class="relatedNews"></ul>"];for (NSDictionary *temDic in newsArray) {[newsString insertString:[NSString stringWithFormat:@"<li><a>%@</a></li>", [temDic objectForKey:@"title"]] atIndex:newsString.length-5];}NSString *htmlPath = [[NSBundle mainBundle] pathForResource:@"entry" ofType:@"html"];NSMutableString *htmlString = [NSMutableString stringWithContentsOfFile:htmlPath encoding:NSUTF8StringEncoding error:nil];NSLog(@"%@", htmlString);NSString *cssPath = [[NSBundle mainBundle] pathForResource:@"entry" ofType:@"css"];NSString *cssString = [NSString stringWithContentsOfFile:cssPath encoding:NSUTF8StringEncoding error:nil];NSLog(@"%@", cssString);[htmlString replaceOccurrencesOfString:@"%added_styles%" withString:cssString options:NSLiteralSearch range:NSMakeRange(0, [htmlString length])];[htmlString replaceOccurrencesOfString:@"%source%" withString:sourceString options:NSLiteralSearch range:NSMakeRange(0, [htmlString length])];[htmlString replaceOccurrencesOfString:@"%title%" withString:titleString options:NSLiteralSearch range:NSMakeRange(0, [htmlString length])];[htmlString replaceOccurrencesOfString:@"%pubdate%" withString:pubdateString options:NSLiteralSearch range:NSMakeRange(0, [htmlString length])];[htmlString replaceOccurrencesOfString:@"%author%" withString:authorString options:NSLiteralSearch range:NSMakeRange(0, [htmlString length])];[htmlString replaceOccurrencesOfString:@"%content%" withString:contentString options:NSLiteralSearch range:NSMakeRange(0, [htmlString length])];[htmlString replaceOccurrencesOfString:@"%font_size%" withString:@"font_size_2" options:NSLiteralSearch range:NSMakeRange(0, [htmlString length])];[htmlString replaceOccurrencesOfString:@"%relatedNews%" withString:newsString options:NSLiteralSearch range:NSMakeRange(0, [htmlString length])];NSLog(@"%@", htmlString);//        [[responseObject firstObject] objectForKey:@"content"];[_myWebView loadHTMLString:htmlString baseURL:nil];
//        [_myWebView stringByEvaluatingJavaScriptFromString:<#(NSString *)#>]} failure:^(AFHTTPRequestOperation *operation, NSError *error) {NSLog(@"Error: %@", error.localizedDescription);}];// Connection[operation start];

本文发布于:2024-02-05 01:47:29,感谢您对本站的认可!

本文链接:https://www.4u4v.net/it/170721258461905.html

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。

下一篇:回溯算法
标签:网络   html
留言与评论(共有 0 条评论)
   
验证码:

Copyright ©2019-2022 Comsenz Inc.Powered by ©

网站地图1 网站地图2 网站地图3 网站地图4 网站地图5 网站地图6 网站地图7 网站地图8 网站地图9 网站地图10 网站地图11 网站地图12 网站地图13 网站地图14 网站地图15 网站地图16 网站地图17 网站地图18 网站地图19 网站地图20 网站地图21 网站地图22/a> 网站地图23