网络解析html
来源:互联网 发布:彩妆怎么去个淘宝名字 编辑:程序博客网 时间:2024/06/02 07:04
// Request: My API (http://watch-cdn.idailywatch.com/api/list/cover/zh-hans?page=1&ver=iphone&app_ver=8) NSURL *URL = [NSURL URLWithString:@"http://watch-cdn.idailywatch.com/api/list/cover/zh-hans?page=1&ver=iphone&app_ver=8"]; NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:URL]; request.HTTPMethod = @"GET"; request.timeoutInterval = 30; // Request Operation AFHTTPRequestOperation *operation = [[AFHTTPRequestOperation alloc] initWithRequest:request]; operation.responseSerializer = [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", (long)operation.response.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];
0 0
- 网络解析html
- HTML解析,网络爬虫
- HTML解析,网络爬虫
- 【解析HTML】HTML解析,网络爬虫
- Python 网络编程测试-HTML解析
- 网络爬虫2----JSoup解析HTML
- python网络爬虫-复杂HTML解析
- 网络爬虫--数据处理,jsoup工具解析html,dom4j解析xml
- 【使用JSOUP实现网络爬虫】解析一个HTML字符串
- 网络爬虫之html获取和解析(Java)
- jsoup解析网络HTML页,基本的使用方法
- 【使用JSOUP实现网络爬虫】解析一个HTML字符串
- android中的网络解析xml,json,html框架
- HTML 解析
- html 解析
- 解析HTML
- html 解析
- 解析HTML
- 【网络爬虫】【java】微博爬虫(三):庖丁解牛——HTML结构分析与正则切分
- Java 虚拟机类加载机制
- 42 session
- 【网络爬虫】【java】微博爬虫(四):数据处理——jsoup工具解析html、dom4j读写xml
- Xtext是什么
- 网络解析html
- DIY台式机
- [Leetcode]Maximum Product Subarray
- java的加载与执行
- 错误简单记录分析1
- 2014/10/1 MATLAB R2010b 安装参考的图文教程(附有Matlab我自己下载用的链接)
- oracle查询表信息(索引,外键,列等......)
- 知识点杂记
- CAN总线自收发程序