Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get the HTML source of a page from a HTML link in Android?

I'm working on an application that needs to get the source of a web page from a link, and then parse the html from that page.

Could you give me some examples, or starting points where to look to start writing such an app?

like image 217
Praveen Avatar asked Mar 11 '10 08:03

Praveen


People also ask

Can you view page source on mobile?

While there is a way to view the HTML source of a website on Android or iPhone through the app, you can also view it without it by using the View Page Source website. This tool allows you to view the formatted version of the source code of any website right in the browser.

How do you view the source file in HTML?

View Source Using View Page Source Fire up Chrome and jump to the webpage you want to view the HTML source code. Right-click the page and click on “View Page Source,” or press Ctrl + U, to see the page's source in a new tab. A new tab opens along with all the HTML for the webpage, completely expanded and unformatted.


1 Answers

You can use HttpClient to perform an HTTP GET and retrieve the HTML response, something like this:

HttpClient client = new DefaultHttpClient(); HttpGet request = new HttpGet(url); HttpResponse response = client.execute(request);  String html = ""; InputStream in = response.getEntity().getContent(); BufferedReader reader = new BufferedReader(new InputStreamReader(in)); StringBuilder str = new StringBuilder(); String line = null; while((line = reader.readLine()) != null) {     str.append(line); } in.close(); html = str.toString(); 
like image 128
Mark B Avatar answered Sep 27 '22 22:09

Mark B