> For the complete documentation index, see [llms.txt](https://philm.gitbook.io/philm-ios-wiki/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://philm.gitbook.io/philm-ios-wiki/mei-zhou-yue-du/webview-jia-zai-bu-fen-wang-ye.md).

# webview加载部分网页

有时候在用webview 可能加载网页的部分内容, 我以www\.baidu.com首页为例子 getElementsByClassName

在webViewDidFinishLoad中加入下面代码

```
- (void)webViewDidFinishLoad:(UIWebView *)webView
{

      NSString * jStr = @"var divsToHide = document.getElementsByClassName('s_form_wrapper soutu-env-mac soutu-env-index');"

      "for(var i=0; i < divsToHide.length; i++)"
      "{"
      //"alert(theThumbs);"
      "divsToHide[i].style.visibility = 'hidden';"
      "divsToHide[i].style.display = 'none';"
      "}";
      [locationWebView stringByEvaluatingJavaScriptFromString:test];

}
```

这个 DIV 就可以被隐藏了

扩展阅读

* [UIWebView与JS的深度交互](http://kittenyang.com/webview-javascript-bridge/)
