마스터Q&A 안드로이드는 안드로이드 개발자들의 질문과 답변을 위한 지식 커뮤니티 사이트입니다. 안드로이드펍에서 운영하고 있습니다. [사용법, 운영진]

안드로이드 스튜디오 jericho 파싱 하는법좀 알려주세요 [closed]

0 추천

미세먼지 값을 받아오려고 하는데 하루죙일 해도 안되네요

http://www.airkorea.or.kr/sidoCompare?itemCode=10007

여기에서 일평균 최대값 최소값 구하려고 하는데 잘 안되요.

 

        textView = (TextView) findViewById(R.id.text);
        parsing_url = "http://www.airkorea.or.kr/sidoCompare?itemCode=10007";

        Runnable task = new Runnable() {
            public void run() {
                getData(parsing_url);
            }
        };
        thread = new Thread(task);
        thread.start();  // 반드시 쓰레드를 해줘야함 그 이유는 아래에서 설명
        try {
            thread.join();  // 쓰레드 작업 끝날때까지 다른 작업들은 대기
        } catch (Exception e) {
        }
        for (int i = 0; i < array.size(); i++) {
            textView.append(array.get(i) + "\n");  // 쓰레드 작업 끝나면 텍스트뷰에 가져온 데이터를 입력
        }
    }
    // 파싱 작업을 하는 메서드
    public ArrayList<String> getData(String strURL) {
        Source source;
        get_data = "";
        array = new ArrayList();
        try {
            URL url = new URL(strURL);
            source = new Source(url);  // 쓰레드를 사용 안하면 여기에서 예외 발생함 그 이유는 아래에서 설명
            Element element = null;
            List<Element> list = source.getAllElements(HTMLElementName.TABLE); // title 태그의 엘리먼트 가져옴

            Element div = source.getAllElements(HTMLElementName.TR).get(3);
            Log.i("head1",list+"");
            textView.setText(""+div.toString());
            Log.i("head",div+"");
            for (int i = 0; i < list.size(); i++) {
                element = list.get(i);
                String attributevalue = element.getAttributeValue("type");  // title 태그의 속성값이 type을 찾는다
                if (attributevalue != null) {
                    TextExtractor textExtractor = element.getTextExtractor();  // 해당 문자값을 가져온다
                    get_data = textExtractor.toString();  // 가져온 값을 스트링으로 변환후
                    array.add(get_data);  // ArrayList에 추가한다
                }
            }
        } catch (Exception e) {
        }
        return array;  // 입력된 배열값을 리턴
    }
}
질문을 종료한 이유: ㅇㅇㅇㅇㅇㅇㅇㅇㅇㅇㅇㅇㅇㅇㅇㅇㅇㅇㅇ
어민 (180 포인트) 님이 2017년 7월 7일 질문
어민님이 2017년 7월 7일 closed
07-07 23:33:33.761 24541-24677/kr.soen.test I/head: <tr>"
                                                                                + "    <td>"+valName+"</td>"
                                                                                + "    <td>"+nullChg(charts[i-1].AREA_1)+"</td>"
                                                                                + "    <td>"+nullChg(charts[i-1].AREA_2)+"</td>"
                                                                                + "    <td>"+nullChg(charts[i-1].AREA_3)+"</td>"
                                                                                + "    <td>"+nullChg(charts[i-1].AREA_4)+"</td>"
                                                                                + "    <td>"+nullChg(charts[i-1].AREA_5)+"</td>"
                                                                                + "    <td>"+nullChg(charts[i-1].AREA_6)+"</td>"
                                                                                + "    <td>"+nullChg(charts[i-1].AREA_7)+"</td>"
                                                                                + "    <td>"+nullChg(charts[i-1].AREA_17)+"</td>"
                                                                                + "    <td>"+nullChg(charts[i-1].AREA_8)+"</td>"
                                                                                + "    <td>"+nullChg(charts[i-1].AREA_9)+"</td>"
                                                                                + "    <td>"+nullChg(charts[i-1].AREA_10)+"</td>"
                                                                                + "    <td>"+nullChg(charts[i-1].AREA_11)+"</td>"
                                                                                + "    <td>"+nullChg(charts[i-1].AREA_12)+"</td>"
                                                                                + "    <td>"+nullChg(charts[i-1].AREA_13)+"</td>"
                                                                                + "    <td>"+nullChg(charts[i-1].AREA_14)+"</td>"
                                                                                + "    <td>"+nullChg(charts[i-1].AREA_15)+"</td>"
                                                                                + "    <td>"+nullChg(charts[i-1].AREA_16)+"</td>"
                                                                                + "</tr>
로그 찍어 놓은 거인데 값으로 안나오고 nullChg(charts[i-1].AREA_1)이렇게 나오는것도 문제에요
...