//联系人:石虎QQ: 1224614774昵称:嗡嘛呢叭咪哄
一、加载视图
- (void)viewDidLoad {
[superviewDidLoad];
NSString *strurl=@"html地址";
UIWebView *web = [[UIWebView alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
web.delegate =self;
[web loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:strurl]]]
[self.view addSubview:web];
}
二、遵守 web 协议方法
//UIWebViewDelegate协议方法
- (void)webViewDidFinishLoad:(UIWebView *)webView {
UIWebView *web = webView;
//获取所有的html
NSString *allHtml =@"document.documentElement.innerHTML";
//获取网页title
NSString *htmlTitle =@"document.title";
//获取网页的一个值
NSString *htmlNum =@"document.getElementById('title').innerText";
//最后调用stringByEvaluatingJavaScriptFromString获取相应内容
//例如如下代码获取Html内容
NSString *allHtmlInfo = [web stringByEvaluatingJavaScriptFromString:allHtml];
谢谢!!!