게시판 즐겨찾기
편집
드래그 앤 드롭으로
즐겨찾기 아이콘 위치 수정이 가능합니다.
기상청 날씨 받아오기
게시물ID : programmer_20924짧은주소 복사하기
작성자 : 으낭
추천 : 1
조회수 : 2591회
댓글수 : 4개
등록시간 : 2017/06/30 04:27:19
//http://newsky2.kma.go.kr/service/SecndSrtpdFrcstInfoService2/ForecastGrib?ServiceKey=인증키&base_date=20170627&base_time=1800&nx=61&ny=126&pageNo=1&numOfRows=7&_type=xml
// key = 공공데이터 포털 동네 예보정보 조회서비스 신청 후 발급
// date = YYYYMMDD
// hour = HH00  
// x, y = 동네예보조회서비스_격자_위경도(20170201).xlsx  | http://www.kma.go.kr/weather/forecast/digital_forecast_map.jsp

string URI = "http://newsky2.kma.go.kr/service/SecndSrtpdFrcstInfoService2/ForecastGrib?ServiceKey="+
                key+ "&base_date=" +
                date+"&base_time=" + 
                hour + "00"+ "&nx=" + 
                x + "&ny=" + y + 
                "&pageNo=1&numOfRows=7"+
                "&_type=xml";

WebClient webClient = new WebClient() { Encoding = Encoding.UTF8 };
XmlDocument xmlDoc = new XmlDocument();

try
            {
                string[] tempHumi = new string[2];

                LoadedXML = webClient.DownloadString(new Uri(URI));
                xmlDoc.LoadXml(LoadedXML);
                xmlItemsList = xmlDoc.GetElementsByTagName("item");

                foreach (XmlNode nowItem in xmlItemsList)
                {
                    if (nowItem["category"].InnerText == "T1H") // 온도
                    {
                        tempHumi[0] = nowItem["obsrValue"].InnerText; 
                    }
                    else if (nowItem["category"].InnerText == "REH") // 습도
                    {
                        tempHumi[1] = nowItem["obsrValue"].InnerText;
                    }
                }
                WeatherInfoMsg?.Invoke(tempHumi);

            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
                return;
            }
            finally
            {
                xmlDoc = null;
                webClient.Dispose();
            }


집에서 쓰는 프로그램에 날씨가 넣고싶어서..
크롤링을 해야하나 싶었는데 api가 있었네요.
멍청해서 미련한 짓을 할 뻔 했습니다..ㄷㄷ

출처 https://www.data.go.kr/dataset/15000099/openapi.do
전체 추천리스트 보기
새로운 댓글이 없습니다.
새로운 댓글 확인하기
글쓰기
◀뒤로가기
PC버전
맨위로▲
공지 운영 자료창고 청소년보호