1. Are you ready for the Galaxy S20? Here is everything we know so far!

how to get html page source from a link?

Discussion in 'Android Development' started by rafiqsab, Jul 13, 2011.

  1. rafiqsab

    rafiqsab Lurker
    Thread Starter

    hi all,

    i have situation where i need to pass the html page source as a input to the javascript function. so please help me in reading the html page source.


    thanks and regards
    rafiq
     



    1. Download the Forums for Android™ app!


      Download

       
  2. dCoder

    dCoder Newbie

    This method will return the html of a given URL as a String:


    public String getUrlContent(String urlStr) {
    try {
    URL url = new URL(urlStr);
    URLConnection con = null;
    con = url.openConnection();
    String encoding = con.getContentEncoding();
    if (encoding == null) {
    encoding = "ISO-8859-1";
    }
    BufferedReader r = new BufferedReader(new InputStreamReader(con.getInputStream(), encoding));
    StringBuilder sb = new StringBuilder();
    try {
    String s;
    while ((s = r.readLine()) != null) {
    sb.append(s);
    sb.append("\n");
    }
    } finally {
    r.close();
    }
    return sb.toString();
    } catch (IOException ex) {
    return "";
    }
    }
     
Loading...
Similar Threads - html page source
  1. gonen52
    Replies:
    0
    Views:
    490
  2. Gangul
    Replies:
    0
    Views:
    1,589
  3. marp68
    Replies:
    8
    Views:
    1,118
  4. HarryC
    Replies:
    2
    Views:
    917
  5. HarryC
    Replies:
    3
    Views:
    1,188
  6. Kiran Shaw
    Replies:
    1
    Views:
    1,046
  7. midsms
    Replies:
    2
    Views:
    1,743
  8. Philip1982
    Replies:
    0
    Views:
    1,403
  9. Andy Perrett
    Replies:
    3
    Views:
    1,141
  10. jchirag21
    Replies:
    2
    Views:
    8,178

Share This Page

Loading...