zoukankan      html  css  js  c++  java
  • 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;
            }
        }
    
    }
  • 相关阅读:
    【Linux】——sleep无法正常休眠
    【网络——Linux】——IPMI详细介绍【转】
    【Linux】——ctags
    10086 8元套餐
    建置 区域划分
    几何
    孙武
    监察委
    python 内置函数
    Oracle cursor and table
  • 原文地址:https://www.cnblogs.com/langdangyunliu/p/5206453.html
Copyright © 2011-2022 走看看