xcode Objective C - UIWebview 只加载网页的特定部分?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/9780700/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-14 23:42:54  来源:igfitidea点击:

Objective C - UIWebview to load only a certain part of the webpage?

iphonehtmlobjective-cxcodeuiwebview

提问by Alan

I am working with a UIWebview, is there anyway I can just load just the body of a webpage instead of the entire webpage with my UIWebView (aka not load the header and footer)? This website is not mine. But looking at the HTML of this site, I only want to load to div id="mainContent" to /div Either by writing some objective c or javascript?

我正在使用 UIWebview,无论如何我可以只加载网页的正文而不是使用我的 UIWebView 加载整个网页(也就是不加载页眉和页脚)?这个网站不是我的。但是看这个网站的 HTML,我只想加载到 div id="mainContent" 到 /div 要么通过编写一些客观的 c 或 javascript?

Thanks! Alan

谢谢!艾伦

采纳答案by Dru Freeman

With Web-Kit you can parse the incoming HTML and do whatever you like to it (within, legal rights to the site you are reading)

使用 Web-Kit,您可以解析传入的 HTML 并对其进行任何操作(在您正在阅读的网站的合法权利范围内)

Once the data is loaded in you can then push the edited HTML to the WKView fairly easily.

加载数据后,您可以相当轻松地将编辑过的 HTML 推送到 WKView。

If you have an outlet to the webView you can do: (For example a UIWebView in iOS)

如果您有 webView 的插座,您可以执行以下操作:(例如 iOS 中的 UIWebView)

[webView loadHTMLString:htmlString baseURL:nil];
[webView setNeedsDisplay];