Where The Streets Have No Name

jsoup을 이용해서 게시판 목록 추출 본문

Developement/Java

jsoup을 이용해서 게시판 목록 추출

highheat 2011. 9. 7. 15:22
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;

public class Demo2 {
	
	public static void main(String[] args) throws Exception {
		Document doc = Jsoup.connect("http://mlbpark.donga.com/mbs/articleL.php?mbsC=bullpen&cpage=1").get();
		System.out.println(doc.title());
		Elements els = doc.getElementsByClass("G12read");
		Elements els2 = doc.getElementsByClass("A11gray");
		System.out.println("G12read: " + els.size()+"A11gray: "+els2.size());
		
		for (int i=0;i < els.size();i++) {
			Element el = els.get(i);
			Element el2 = els2.get(i);
			if(!el2.text().equals("공지")){
				System.out.println(el2.text() + " - " + el.text());
				Elements childs = el.getElementsByAttribute("href");
				//System.out.println(childs.size());
				if(childs.size() == 2){
					//System.out.println(childs.get(0));
					System.out.println("/mbs/articleVC.php?mbsC=bullpen&mbsIdx="+childs.get(0).attr("title"));
				}
			}
		}
	}	
}