JAVA 获取网页流

 

package com.gethtmlContent;

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

public class getHtmlContent {
    public static void main(String[] args) {

        System.getProperties().put("http.proxyHost", "xx.xx.xx.xx");// 代理服务器IP地址
        System.getProperties().put("http.proxyPort", "xxxx");// 代理服务器端口
        String url = "xxxxx";
        System.out.println(getHtmlConentByUrl(url));
    }

    public static String getHtmlConentByUrl(String ssourl) {
        try {
            URL url = new URL(ssourl);
            HttpURLConnection con = (HttpURLConnection) url.openConnection();

            con.setInstanceFollowRedirects(false);
            con.setUseCaches(false);
            con.setAllowUserInteraction(false);
            con.connect();
            StringBuffer sb = new StringBuffer();
            String line = "";
            BufferedReader URLinput = new BufferedReader(new InputStreamReader(con.getInputStream()));
            while ((line = URLinput.readLine()) != null) {
                sb.append(line);
            }
            con.disconnect();

            return sb.toString().toLowerCase();
        } catch (Exception e) {
            return null;
        }
    }

}

 

posted @ 2016-02-22 10:51  浪荡云流  阅读(607)  评论(0编辑  收藏  举报