使用webView加载页面,去除页面广告

来源:互联网 发布:麦哲伦软件 编辑:程序博客网 时间:2024/05/02 09:50
#import "ViewController.h"

@interface ViewController ()<UIWebViewDelegate>

@property (nonatomic, strong) UIWebView *webView;

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.webView = [[UIWebView alloc] initWithFrame:[UIScreen mainScreen].bounds];
    [self.view addSubview:self.webView];
    self.webView.delegate = self;
    NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:@"http://m.ys137.com/article_803088.html"]];
    [self.webView loadRequest:request];
    //自适应屏幕大小
    self.webView.scalesPageToFit = YES;
}

//UIWebView的代理方法
- (void)webViewDidFinishLoad:(UIWebView *)webView
{
    //具体去除广告的操作
    //查看更详细的操作进入:http://jwdev.cn/2015/09/28/use-javascript-to-delete-web-element/
    [webView stringByEvaluatingJavaScriptFromString:@"document.getElementsByClassName('m-container')[0].style.display = 'none'"];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
1 0
原创粉丝点击