Java URL Read getHTML(String pageURL, String encoding)

Here you can find the source of getHTML(String pageURL, String encoding)

Description

get HTML

License

Apache License

Declaration

public static String getHTML(String pageURL, String encoding) 

Method Source Code


//package com.java2s;
//License from project: Apache License 

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;

public class Main {
    public static String getHTML(String pageURL, String encoding) {

        StringBuilder pageHTML = new StringBuilder();

        try {//from  w w w.j  a  va  2  s  . c o m

            URL url = new URL(pageURL);

            HttpURLConnection connection = (HttpURLConnection) url.openConnection();

            connection.setRequestProperty("User-Agent", "MSIE 7.0");

            BufferedReader br = new BufferedReader(new InputStreamReader(connection.getInputStream(), encoding));

            String line = null;

            while ((line = br.readLine()) != null) {

                pageHTML.append(line);

                pageHTML.append("\r\n");

            }

            connection.disconnect();

        } catch (Exception e) {

            e.printStackTrace();

        }

        return pageHTML.toString();

    }
}

Related

  1. getFileContentFromWeb(final URL srcUrl, final FileOutputStream destination)
  2. getFileSize(String sURL)
  3. getFileSize(URL url)
  4. getFilesizeFromUrl(String urlString)
  5. getFromURL(String URL)
  6. getHtml(String url)
  7. getHtml(String urlString)
  8. getHTML(String urlToRead)
  9. getHTML(String urlToRead)