URL에서 이미지 경로를 불러와 중복제거하여 출력하기 소스 :: JAVA 공작소[SSISO Community]
 
SSISO 카페 SSISO Source SSISO 구직 SSISO 쇼핑몰 SSISO 맛집
추천검색어 : JUnit   Log4j   ajax   spring   struts   struts-config.xml   Synchronized   책정보   Ajax 마스터하기   우측부분

JAVA 공작소
[1]
등록일:2008-11-26 01:54:45 (0%)
작성자:
제목:URL에서 이미지 경로를 불러와 중복제거하여 출력하기 소스
import  java.io.BufferedReader;
import  java.io.InputStreamReader;
import  java.net.URL;
import  java.util.Iterator;
import  java.util.TreeSet;
import  java.util.regex.Matcher;
import  java.util.regex.Pattern;

class  articleRead  {
        
        public  void    getArticle_start()    {
                
                URL    yahoo;
                BufferedReader    in;
                String    inputLine="";
                StringBuffer    pageBuffer=null;
                  
                try  {                        
                        
                        yahoo    =    new    URL("http://ssiso.net");
                        in    =    new    BufferedReader(new    InputStreamReader(yahoo
                                                        .openStream()));

                        
                        pageBuffer    =    new    StringBuffer();

                        while    ((inputLine    =    in.readLine())    !=    null)
                                        pageBuffer.append(inputLine);
                        
                        System.out.println(pageBuffer.toString());
                        
                        getImageLink(pageBuffer.toString());
                        
                        
                        
                }  catch  (Exception  e)  {
                        e.printStackTrace();
                }
                              
        }
                
        public  void  getImageLink(String  pageContent){
                
                /*
                자바에는  Set이라는  클래스가  있습니다.
                자료를  중복을  허용하지  않고  넣는  자료형입니다.
                또  TreeSet이라는  것이  있습니다.  기본적으로  내부적으로  정렬이  되면서  Set의  특성을  가진다고  볼수  있습니다.
                */
                
                Pattern    pattern;
                Matcher    match;
                String  sb="";
                StringBuffer    imageLinkList=null;
                TreeSet  tset;
                Iterator  itor;
                
                try  {
                        tset  =  new  TreeSet();
                        imageLinkList  =  new  StringBuffer();
                        
                        pattern    =    Pattern.compile("<img[^>]*[    src=]?[\"']?[^>\"']+[\"']?[^>]*>");
                        match    =    pattern.matcher(pageContent);
                        while    (match.find())    {
                                sb    =    match.group();
                                tset.add(sb);
                        }
                        
                        itor  =  tset.iterator();
                        while(itor.hasNext())  {
                                System.out.println(itor.next());
                        }
                        
                }  catch  (Exception  e)  {
                        e.printStackTrace();
                }
                
        }
        
}

public  class  ARTICLE  {
        
        public    static    void    main(String[]    args)    {
                
                articleRead  articleRead  =  new  articleRead();
                articleRead.getArticle_start();
                
        }        
}
[본문링크] URL에서 이미지 경로를 불러와 중복제거하여 출력하기 소스
[1]
코멘트(이글의 트랙백 주소:/cafe/tb_receive.php?no=31417
작성자
비밀번호

 

SSISOCommunity

[이전]

Copyright byCopyright ⓒ2005, SSISO Community All Rights Reserved.