首页 > 编程语言 > 详细

JAVA 获取网页流

时间:2016-02-22 12:07:00      阅读:275      评论:0      收藏:0      [点我收藏+]

 

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;
        }
    }

}

 

JAVA 获取网页流

原文:http://www.cnblogs.com/langdangyunliu/p/5206453.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!