• Java 读取网页简易程序


    package com.ibm.downloadtool;
    import java.io.BufferedInputStream;
    import java.net.HttpURLConnection;
    import java.net.URL;
    import java.util.Scanner;

    public class DownLoadTool {

        public static void main(String[] args) {
            // TODO Auto-generated method stub
            
            DownLoadTool d = new DownLoadTool();
            d.downLoadUrl("http://finance.sina.com.cn/");

        }
            //download
            public String downLoadUrl(String addr){
                StringBuffer sb=new StringBuffer();
                try {
                    URL url=new URL(addr);
                    HttpURLConnection con= (HttpURLConnection) url.openConnection();
                    con.setConnectTimeout(1000);
                    con.connect();
                    System.out.println(con.getResponseCode());
                    if(con.getResponseCode()==200){
                        BufferedInputStream bis=new BufferedInputStream(con.getInputStream());
                        Scanner sc=new Scanner(bis,"GBK");
                        while(sc.hasNextLine()){
                            sb.append(sc.nextLine());
                        }
                        sc.close();
                    }
                } catch (Exception e) {

                    e.printStackTrace();
                }
                System.out.println(sb.toString());
                return sb.toString();
            }
        }




  • 相关阅读:
    Maximum sum
    走出迷宫
    取石子游戏
    全排列
    BZOJ3456 城市规划
    【SHOI2016】黑暗前的幻想乡
    【AHOI2012】信号塔
    HDU5730 Shell Necklace
    线性常系数齐次递推关系学习笔记
    矩阵树定理学习笔记
  • 原文地址:https://www.cnblogs.com/TendToBigData/p/10501473.html
Copyright © 2020-2023  润新知