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 = "@font-face {font-family: 'verdana';src: url['file://"+ context.getFilesDir[].getAbsolutePath[]+ "/verdana.ttf'];}body {font-family: 'verdana';}";
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["//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
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
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.
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 //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 //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://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.