Teach, please, how to output from the entire html page in the WebView content only div id="main-content" .

If I understand correctly, then there are 3 ways:

  1. Parse the whole page, and then build a new html from the resulting
  2. Use javascript and show only what i need ( div id="main-content" ).
  3. Use JavaScript and hide everything that I do NOT need ( header class="mh-header" and aside class="mh-sidebar" ).

Since I am quite a beginner "developer", I am very vaguely imagining how to do this. Parsing and rebuilding HTML is very difficult for me. I would like to look at an example of a solution using the second or third method. Dear gurus - share a fraction of your knowledge. :)

    1 answer 1

    Found the answer on this page . This answer is suitable for the third solution.

    I used the following code:

      webView.loadUrl("javascript:(function() { " + "var head = document.getElementsByTagName('header')[0];" + "head.parentNode.removeChild(head);" + "})()"); webView.loadUrl("javascript:(function() { " + "var head = document.getElementsByTagName('aside')[0];" + "head.parentNode.removeChild(head);" + "})()"); 

    True when loading the page for a moment appears in its full form, but then disappears.