메뉴 건너뛰기

Bigdata, Semantic IoT, Hadoop, NoSQL

Bigdata, Hadoop ecosystem, Semantic IoT등의 프로젝트를 진행중에 습득한 내용을 정리하는 곳입니다.
필요한 분을 위해서 공개하고 있습니다. 문의사항은 gooper@gooper.com로 메일을 보내주세요.


특정페이지를 jsoup을 이용하여 파싱하는 샘플소스

import org.apache.derby.tools.sysinfo;
import org.jsoup.nodes.Document;
import org.jsoup.select.Elements;
import org.jsoup.Jsoup;  

public class JSoupTest {

	public static void main(String[] args) {
		Document doc = null;
		try {
			//doc = Jsoup.connect("http://www.javatpoint.com").get();
			doc = Jsoup.connect("http://www.xxx.com/product/product_list.php?cods=ca1&aci_code=11")
					.data("page", "5")
					.data("srch_pagesize","30")
					.userAgent("Mozilla")
					.post();
		} catch (Exception e) {
			System.out.println("exception : "+e.getMessage());
		}
		
		//String title = doc.title();
		//System.out.println("title : "+title);
		
		//System.out.println("doc : "+doc.toString());
		
		// tbody에 있는 tr을 모두 구함
		Elements trs  = doc.select("tbody tr");
		System.out.println("tr개수 : "+trs.size());
		
		// 각 tr별로 처리함
		for(int i = 1; i < trs.size(); i++) {
			System.out.println(trs.get(i));
		
			// tr밑에 있는 td를 추출한다.
			Elements tds = trs.select("td");
			System.out.println("물품명 :"+tds.get(1).text().trim());
			
			Elements href = tds.get(0).select("a[href]");
			Elements img = tds.get(0).select("img[src]");
			
			// href속성의 값을 구하면서 완성된 URL를 리턴한다.
			System.out.println("물품 상세 보기 링크  : "+href.attr("abs:href").toString());
			// src속성의 값을 구하면서 완성된 URL를 리턴한다.
			System.out.println("물품 이미지 링크 : "+img.attr("abs:src").toString());
			
			System.out.println("현재가 : "+tds.get(2).text().trim());
			System.out.println("배송비 : "+tds.get(3).text().trim());
			System.out.println("입찰수 : "+tds.get(4).text().trim());
			System.out.println("판매자 : "+tds.get(5).text().trim());
			System.out.println("종료일 : "+tds.get(6).text().trim());

			System.out.println("========================================================================================");
		}
		
		
	}
}


번호 제목 글쓴이 날짜 조회 수
33 [gson]mongodb의 api를 이용하여 데이타를 가져올때 "com.google.gson.stream.MalformedJsonException: Unterminated object at line..." 오류발생시 조치사항 총관리자 2017.12.11 4389
32 lagom-windows용 build.sbt파일 내용 총관리자 2017.10.12 60
31 lagom-linux용 build.sbt파일 내용 총관리자 2017.10.12 1300
30 lagom의 online-auction-java프로젝트 실행시 "Could not find Cassandra contact points, due to: ServiceLocator is not bound" 경고 발생시 조치사항 총관리자 2017.10.12 219
29 python3.5에서 numpy버젼에 따른 문제점을 조치하는 방법및 pymysql import할때 오류 발생시 조치사항 총관리자 2017.09.28 80
28 python test.py실행시 "ImportError: No module named pyspark" 혹은 "ImportError: No module named py4j.protocol"등의 오류 발생시 조치사항 총관리자 2017.07.04 764
» [Jsoup]특정페이지를 jsoup을 이용하여 파싱하는 샘플소스 총관리자 2017.04.18 205
26 [jsoup]Jsoup Tutorial 총관리자 2017.04.11 146
25 [메모리 덤프파일 분석] 총관리자 2017.03.31 198
24 [springframework]Caused by: org.mariadb.jdbc.internal.util.dao.QueryException: Could not read resultset: unexpected end of stream, read 0 bytes from 4 오류 발생시 조치사항 총관리자 2017.01.23 680
23 [tomcat] logrotate를 이용하여 catalina.out로그파일 일별로 로테이션 저장하기 file 총관리자 2017.01.18 318
22 List<Map<String, String>>형태의 데이타에서 중복제거 하는 방법 총관리자 2016.12.23 1679
21 Class.forName을 이용한 메서드 호출 샘플소스 총관리자 2016.12.21 100
20 Collections.sort를 이용한 List<Map<String, String>>형태의 데이타 정렬 소스 총관리자 2016.12.15 45
19 Collections.sort를 이용한 List<User>형태의 데이타 정렬(숫자, 문자에 대해서 각각 asc/desc및 복합정렬) 총관리자 2016.12.15 114
18 Eclipse실행시 Java was started but returned exit code=1이라는 오류가 발생할때 조치방법 총관리자 2016.11.07 397
17 java스레드 덤프 분석하기 file 총관리자 2016.11.03 111
16 mybatis와 spring을 org.apache.commons.dbcp2.BasicDataSource의 DataSource로 연동할때 DB설정(참고) 총관리자 2016.10.31 990
15 Caused by: java.sql.SQLNonTransientConnectionException: Could not read resultset: unexpected end of stream, read 0 bytes from 4 오류시 확인/조치할 내용 총관리자 2016.10.31 3758
14 VisualVM 1.3.9을 이용한 JVM 모니터링 file 총관리자 2016.10.27 332

A personal place to organize information learned during the development of such Hadoop, Hive, Hbase, Semantic IoT, etc.
We are open to the required minutes. Please send inquiries to gooper@gooper.com.

위로