资料来源:http://blog.sina.com.cn/s/blog_6d58b63101010x5v.html
用的是UIWebView解析的方法
UIWebView *webView = [[UIWebView alloc] init];
NSURLRequest *rr =[NSURLRequest requestWithURL:url];
[webView loadRequest:rr];
webView.delegate = self; //记得遵循代理 UIWebViewDelegate
[self.view addSubview:webView];
#pragma mark - UIWebViewDelegate
-(void)webViewDidFinishLoad:(UIWebView *)webView{
NSLog(@"网页加载完成才能获取");
NSString *lJs2 = @"document.documentElement.innerText"; //根据标识符获取不同内容
NSString *lHtml2 = [webView stringByEvaluatingJavaScriptFromString:lJs2];
NSLog(@"网页内容为: %@",lHtml2);
}
上面讲的标识符还有很多类型
thisURL = document.URL;
thisHREF = document.location.href;
thisSLoc = self.location.href;
thisDLoc = document.location;
thisTLoc = top.location.href;
thisPLoc = parent.document.location;
thisTHost = top.location.hostname;
thisHost = location.hostname;
thisTitle = document.title;
thisProtocol = document.location.protocol;
thisPort = document.location.port;
thisHash = document.location.hash;
thisSearch = document.location.search;
thisPathname = document.location.pathname;
thisHtml = document.documentElement.innerHTML;
thisBodyText = document.documentElement.innerText;//获取网页内容文字
thisBodyText = document.body.innerText;//获取网页内容文字 怎么和上一个一样?有知道的请解释
网友评论