Notice
Recent Posts
Recent Comments
Link
250x250
| 일 | 월 | 화 | 수 | 목 | 금 | 토 |
|---|---|---|---|---|---|---|
| 1 | 2 | 3 | 4 | 5 | 6 | |
| 7 | 8 | 9 | 10 | 11 | 12 | 13 |
| 14 | 15 | 16 | 17 | 18 | 19 | 20 |
| 21 | 22 | 23 | 24 | 25 | 26 | 27 |
| 28 | 29 | 30 |
Tags
- oracle
- 서버
- 코드 테스트
- 코드테스트
- java
- BACK-END
- 자바스크립트
- 스프링
- JavaScript
- jsp
- 정리
- 자바
- 디자인 패턴
- MySQL
- 알고리즘
- 데이터베이스
- 스프링부트
- node.js
- jpa
- 프로그래머스
- SQL
- spring
- Next.js
- 쿼리
- 오라클
- 프런트엔드
- 백엔드
- 미니정리
- 프론트엔드
- web
Archives
- Today
- Total
참치코더의 꿈 메모장
2021/09/17 공공데이터 포털 데이터 가져오기 - Java 본문
728x90
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
|
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLEncoder;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
import org.apache.log4j.Logger;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.NodeList;
import org.xml.sax.SAXException;
public class Project2 {
private static Logger log = Logger.getLogger(Project2.class); //log4j 연동
public static void main(String[] args) throws ParserConfigurationException, SAXException, IOException {
String svcKey = "=서비스키";
URL url = new URL("http://api.visitkorea.or.kr/openapi/service/rest/KorService/areaCode"
+"?" + URLEncoder.encode("ServiceKey","UTF-8") + svcKey
//+"&" + URLEncoder.encode("ServiceKey","UTF-8") + "=" + URLEncoder.encode(svcKey +"(URL - Encode)", "UTF-8")
+"&" + URLEncoder.encode("numOfRows","UTF-8") + "=" + URLEncoder.encode("10", "UTF-8")
+"&" + URLEncoder.encode("pageNo","UTF-8") + "=" + URLEncoder.encode("1", "UTF-8")
+"&" + URLEncoder.encode("MobileOS","UTF-8") + "=" + URLEncoder.encode("ETC", "UTF-8")
+"&" + URLEncoder.encode("MobileApp","UTF-8") + "=" + URLEncoder.encode("AppTest", "UTF-8")
+"&" + URLEncoder.encode("arrange","UTF-8") + "=" + URLEncoder.encode("A", "UTF-8")
+"&" + URLEncoder.encode("listYN","UTF-8") + "=" + URLEncoder.encode("Y", "UTF-8")
+"&" + URLEncoder.encode("areaCode","UTF-8") + "=" + URLEncoder.encode("2", "UTF-8")
+"&" + URLEncoder.encode("eventStartDate","UTF-8") + "=" + URLEncoder.encode("20210101", "UTF-8")
);
//System.out.println(url);
DocumentBuilder builder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
// DOM 파서로부터 입력받은 문서내용을 파싱하도록 요청
Document document = builder.parse(url.toString());
// DOM Document 객체로부터 루트 앨리먼트 객체 가져오기
Element root = document.getDocumentElement();
// item 태그요소 가져와서 NodeList에
NodeList itemNodeList = root.getElementsByTagName("item");
//String code = root.getElementsByTagName("code").item(0).getTextContent();
for (int i = 0; i < itemNodeList.getLength(); i++) {
Element element = (Element) itemNodeList.item(i);
String code = root.getElementsByTagName("code").item(i).getTextContent();
String name = root.getElementsByTagName("name").item(i).getTextContent();
String rnum = root.getElementsByTagName("rnum").item(i).getTextContent();
System.out.println("지역코드\t지역명\t일련번호");
System.out.println("=======================================");
System.out.println(code+"\t"+name+"\t"+rnum );
System.out.println("=======================================");
}
}
}
|
cs |
728x90
'잡다한 웹지식' 카테고리의 다른 글
| 알고리즘 4일차 - 프로그래머스 기출 문제 5번 / 물 부족 문제 (0) | 2025.04.22 |
|---|---|
| 알고리즘 3일차 - 프로그래머스 기출 문제 5번 / 심폐소생술 (0) | 2025.04.20 |
| 알고리즘 2일차 - 프로그래머스 기출 문제 4번 / 병과분류 (0) | 2025.04.16 |
| 알고리즘 1일차 - 프로그래머스 기출 문제 3번 / 수 나누기 (0) | 2025.04.16 |
| 2021/09/11 - MVC 패턴은 뭘까?? (Model-View-Controller) (0) | 2021.09.11 |
Comments