BufferedReader獲取網站裏的dom元素

public class HttpURLConnect{
    public static void main(String[] args){
        try{
            URL urlmy = new URL("http://www.sina.com");
           
            HttpURLConnection con = (HttpURLConnection) urlmy.openConnection();
            con.setRequestProperty("User-Agent","Mozilla/4.0 (compatible; MSIE 5.0; Windows NT; DigExt)");
            con.setFollowRedirects(true);
            con.setInstanceFollowRedirects(true);
            con.connect();
           
            BufferedReader br = new BufferedReader(new InputStreamReader(con.getInputStream()));
           
            String s = "";         
            StringBuffer sb = new StringBuffer();         
            while ((s = br.readLine()) != null){
                sb.append(s + "\r\n");
            }         
            System.out.println(sb.toString());
        }catch (Exception e{
            e.printStackTrace();
        }
    }
}
輸出網站的所有dom元素,快速扒網頁。
發佈了33 篇原創文章 · 獲贊 3 · 訪問量 2萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章