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;
            }
        }
    
    }
  • 相关阅读:
    连续子数组的最大和
    孩子们的游戏(圆圈中最后剩下的数)
    左旋转字符串
    业界难题-“跨库分页”的四种方案
    InnoDB意向锁的作用
    Linux下Fork与Exec使用
    minixml的安装教程
    main()函数的形参
    结构体数组初始化
    fork函数详解
  • 原文地址:https://www.cnblogs.com/langdangyunliu/p/5206453.html
Copyright © 2011-2022 走看看