1

I'm building an app which needs to:

  • Open a URL and show the webpage in a webview;
  • Parse che HTML code with JSoup in order to extract all the links in the webpage.

Code i'm using for showing the webpage in the webview:

WebView webview = new WebView(this);
 setContentView(webview);
 webview.loadUrl("http://www.mywebpage.com");

The JSoup request:

Document doc  = Jsoup.connect("http://www.mywebpage.com").get()

Now i nave a doubt to clarify: will my URL receive two different HTML requests from the app? If so, is there a way to perform both the activities (render the webpage and parse the HTML source) downloading the webpage with only one request?

I'm thinking to load the URL through an HTTPUrlConnection, then send the HTML to the engine forma the webview rendering and to Jsoup for the parsing. Could it work?

Stefano
  • 389
  • 2
  • 15

1 Answers1

2

Yes, now you execute two different requests.

Jsoup has a method parse which allows you to parse a HTML block passed as string and then you can show the HTML of the page using webView.loadData(htmlResponse, "text/html", null);.

The other way, execute the request from WebView and then take the HTML, it require more code, here an answer with the code.

What is better for you? It depends. You should try or give us a little bit more context

Maybe the first approach will limit you a bit (from a security view), you get limited on what you can do because you set the code manually and not from the server but i'm not sure about that.

Community
  • 1
  • 1
Marco Acierno
  • 14,682
  • 8
  • 43
  • 53