#import "ViewController.h"
@interface ViewController ()<UIWebViewDelegate>
@end
@implementation ViewController
//每次加载网页请求都会走该方法
- (void)webViewDidFinishLoad:(UIWebView *)webView{
//NSString *js = @"document.getElementById('btn')";
//获取body标签中的所有标签内容
//NSString *js = @"document.getElementsByTagName('body')[0].innerHTML";
//获取body标签, 然后用父标签删除子标签,删除body中的img标签
NSString *js = @"var body = document.getElementsByTagName('body')[0].innerHTML; body.removeChild('img');";
NSString *content = [webView stringByEvaluatingJavaScriptFromString:js];
NSLog(@"%@", content);
}
- (void)viewDidLoad {
[super viewDidLoad];
//服务器文件URL地址
//http://172.21.62.99/train/index4.html
UIWebView *web = [[UIWebView alloc] initWithFrame:self.view.frame];
[self.view addSubview:web];
web.delegate =self;
//加载webView(请求index4.html文件)
[web loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"http://172.21.62.99/train/index4.html"]]];
}```
网友评论