U E D R , A S I H C RSS

JavaHTML Parsing/2011년프로�트



1. 목�


API없� Java HTML파싱� 통해 TEXT를 �어오는게 목�.

HOW???



2. ì§„í–‰

2.1. 페�지 �어오기


어디서 �어온 코드.

import java.net.URL;
 import java.net.URLConnection;
 import java.net.MalformedURLException;

 import java.io.InputStream;
 import java.io.InputStreamReader;
 import java.io.BufferedReader;
 import java.io.IOException;

 public class URLConn{
	 
     public static void main(String args[]){
         URL url;//URL 주소 �체
        URLConnection connection;//URL접�� 가지는 �체
        InputStream is;//URL접��서 내용� �기위한 Stream
         InputStreamReader isr;
         BufferedReader br;
        
         try{
             //URL�체를 �성하고 해당 URL로 접�한다..
             url = new URL("http://www.hufslife.com/");
             connection = url.openConnection();

             //내용� �어오기위한 InputStream�체를 �성한다..
             is = connection.getInputStream();
             isr = new InputStreamReader(is);
             br = new BufferedReader(isr);

             //내용� �어서 화면� 출력한다..
             String buf = null;
             while(true){
                 buf = br.readLine();
                 if(buf == null) break;
                 System.out.println(buf);
             }
         }catch(MalformedURLException mue){
             System.err.println("잘못� URL입니다. 사용법 : java URLConn http://hostname/path]");
             System.exit(1);
         }catch(IOException ioe){
             System.err.println("IOException " + ioe);
             ioe.printStackTrace();
             System.exit(1);
         }
     }
 };

Valid XHTML 1.0! Valid CSS! powered by MoniWiki
last modified 2021-02-07 05:23:30
Processing time 0.0054 sec