How can i get html code from url in android?

I was wondering if is any way to get HTML code from any url and save that code as String in code? I have a method:

private String getHtmlData(Context context, String data){
    String head = "";
    String htmlData= ""+head+""+data+"" ;
    return htmlData;
 }

and I want to get this "data" from url. How I can do that?

asked Jun 10, 2013 at 8:09

Try this (wrote it from the hand)

URL google = new URL("http://www.google.com/");
BufferedReader in = new BufferedReader(new InputStreamReader(google.openStream()));
String input;
StringBuffer stringBuffer = new StringBuffer();
while ((input = in.readLine()) != null)
{
    stringBuffer.append(input);
}
in.close();
String htmlData = stringBuffer.toString();

answered Jun 10, 2013 at 8:16

How can i get html code from url in android?

eMieMi

5,33610 gold badges59 silver badges107 bronze badges

6

Sure you can. That's actually the response body. You can get it like this:

HttpResponse response = client.execute(post);
String htmlPage = EntityUtils.toString(response.getEntity(), "ISO-8859-1");

answered Jun 10, 2013 at 8:15

EnrichmanEnrichman

11k11 gold badges69 silver badges98 bronze badges

take a look at this please, any other parser will work too, or you can even make your own checking the strings and retrieving just the part you want.

answered Jun 10, 2013 at 8:14

How can i get html code from url in android?

Neron TNeron T

3692 silver badges8 bronze badges

Tap once in the address bar and move the cursor to the front of the URL.,Open the web page whose source code you want to view.,Type view-source: and tap Enter or Go.,Open Opera and navigate to the web page whose source code you want to view.

  1. Tap Save in the top-right corner to save the bookmark.
  2. Copy the entire JavaScript code snippet below.

javascript: (function() {
   var a = window.open('about:blank').document;
   a.write('Source code of ' + location.href);
   a.close();
   var b = a.body.appendChild(a.createElement('pre'));
   b.style.overflow = 'auto';
   b.style.whiteSpace = 'pre-wrap';
   b.appendChild(a.createTextNode(document.documentElement.innerHTML))
})();


Suggestion : 2

If this is your site, make sure that the filename case matches the URL. For root URLs (like http://example.com/) you must provide an index.html file. , The site configured at this address does not contain the requested file.

The site configured at this address does not contain the requested file.

If this is your site, make sure that the filename case matches the URL.
For root URLs (like http://example.com/) you must provide an index.html file.


Suggestion : 3

Although on Android Chrome, I have always prepend the view-source: to any URL to view source of that web page f.e., Jabran Rafique Permalink to comment# August 10, 2021 Nice tool. Although on Android Chrome, I have always prepend the view-source: to any URL to view source of that web page f.e. view-source:jabran.me Reply ,on android (not sure about ios) in firefox and chrome you can just prepend “view-source:” in the url to get the same behavoir as on desktop browsers, Mirco Permalink to comment# August 11, 2021 on android (not sure about ios) in firefox and chrome you can just prepend “view-source:” in the url to get the same behavoir as on desktop browsers Reply

Nice tool.

Although on Android Chrome, I have always prepend the view-source: to any URL to view source of that web page f.e.

You can also type view-source: before the url.

I always use Eruda for this. Execute the following bookmarklet:

javascript:(function () { var script = document.createElement('script'); script.src="//cdn.jsdelivr.net/npm/eruda"; document.body.appendChild(script); script.onload = function () { eruda.init() } })();

javascript: (function() {
   var script = document.createElement('script');
   script.src = "//cdn.jsdelivr.net/npm/eruda";
   document.body.appendChild(script);
   script.onload = function() {
      eruda.init()
   }
})();


Suggestion : 4

Most of the times, when we visit a nice looking website, we always want to look at it's HTML source code. On desktop browsers, we simple just right-click and click on "view page source" from the context menu but there's no option like this on mobile devices. So then, how do we view the source code on a mobile device?,Visit the website which you want to view it's source code. ,Click inside the address bar and append view-source: before the url of the website. ,Built on Forem — the open source software that powers DEV and other inclusive communities.

Most of the times, when we visit a nice looking website, we always want to look at it's HTML source code. On desktop browsers, we simple just right-click and click on "view page source" from the context menu but there's no option like this on mobile devices. So then, how do we view the source code on a mobile device?

If we are to observe carefully, whenever we click on "view page source" on a desktop browser, it opens a new url in this format view-source:https://path/to/url.
If we apply this same trick on a mobile device, it works as expected.

Click inside the address bar and append view-source: before the url of the website.


How do I view the HTML code of a website on mobile?

So then, how do we view the source code on a mobile device?.
Visit the website which you want to view it's source code..
Click inside the address bar and append view-source: before the url of the website..
Click the send button and the page will load with the source code of the file..

How do I extract HTML from a website?

Open your browser and navigate to the page for which you wish to view the HTML..
Right-click on the page to open the right-click menu after the page finishes loading..
Click the menu item that allows you to view the source. ... .
When the source page opens, you'll see the HTML code for the full page..

Can I download HTML in Android?

Yes, that's right—coding on your Android device is not only possible, but also popular. The top HTML editors in the Google Play Store have been downloaded millions of times, proving both professionals and enthusiasts increasingly view the operating system as a viable productivity platform.

Where does Android save HTML files?

Method 1.
Step 2: Go to the app > right-click > New > Folder > Asset Folder and create the asset folder..
Step 3: Android Studio will open a dialog box. ... .
Step 4: The asset folder has been created as shown in the below image. ... .
Step 5: Provide a name to your file as shown below..