How to retrieve HTML content from WebView (as a string)

前端 未结 6 2150
旧巷少年郎
旧巷少年郎 2020-11-30 00:55

How do I retrieve all HTML content currently displayed in a WebView?

I found WebView.loadData() but I couldn\'t find the opposite equivalent (e.g. WebVi

6条回答
  •  醉酒成梦
    2020-11-30 01:11

    You can intercept the HTTP requests made by the WebView, and then modify the HTML to include whatever JavaScript functions you need to communicate with the HTML page. You intercept HTTP requests via the WebViewClient shouldInterceptRequest() method.

    Using this mechanism you can get access to the loaded page by loading it yourself, modify it before passing it on to the WebView, and even cache it locally if you want.

提交回复
热议问题