7

I need to download an HTML page programmatically and then get its HTML. I am mainly concerned with the downloading of the page. If I download the page, where will I put it?

Will I have to keep in an String variable? If yes then how?

halfer
  • 19,824
  • 17
  • 99
  • 186
Fahad
  • 281
  • 2
  • 3
  • 4
  • 1
    Here is my answer from duplicate question. http://stackoverflow.com/a/14343789/1237023 – Julian Apr 06 '13 at 20:46
  • Possible duplicate of [How to get the html-source of a page from a html link in android?](https://stackoverflow.com/questions/2423498/how-to-get-the-html-source-of-a-page-from-a-html-link-in-android) – halfer Aug 07 '18 at 09:51

2 Answers2

8

This site provides a good explanation on how to download a file, and also how to set the location to where it should be stored. You do not have to, and should not, keep it in a string variable. If you are to manipulate the data I would suggest you use an XML parser.

hanspeide
  • 2,819
  • 4
  • 25
  • 33
0

You can call this method in doInBackground of AsyncTask

String html = "";
String url = "ENTER URL TO DOWNLOAD";
HttpClient client = new DefaultHttpClient();
HttpGet request = new HttpGet(url);
HttpResponse response = client.execute(request);
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();
Zar E Ahmer
  • 33,936
  • 20
  • 234
  • 300