我怎样才能只显示网站的内容?

How can i display only the content of a website?

我只需要显示网站的一部分,基本上是网站的内容部分。

我可以用 uiwebkit 显示网站,但是,我不想显示整个网站,而只想显示网页的内容部分。我不知道该怎么做,因为我从来没有这样做过,我做了一些 google 搜索,但在 ios / swift.

上找不到任何东西

我该怎么做?谢谢

您可以使用 WKNavigationDelegate 来实现 did finish webview 的功能在此功能中,您可以隐藏网站的特定内容。

func webView(_ webView: WKWebView, didFinish navigation: WKNavigation!) {


    let removeelementid = "javascript:(function() { " + "document.getElementsByClassName('td-header-menu-wrap-full td-container-wrap')[0].style.display=\"none\"; " + "})()"
    webView.evaluateJavaScript(removeelementid) { (res, error) in
        if error != nil
        {
            print("Error")
        }
        else
        {
            //do any thing
        }
    }
}



func webView(_ webView: WKWebView, didFail navigation: WKNavigation!, withError error: Error) {
    print(error.localizedDescription)
}

如您所见,我正在通过其 class 名称删除网络的特定内容 td-header-menu-wrap-full td-container-wrap

右键单击该网站 -> 单击“检查”。选择 class 内容名称并调用此函数。希望对你有帮助。