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

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

0 추천
        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.TBODY); // title 태그의 엘리먼트 가져옴
            Log.i("list.Element",list+"");

            for (int i = 0; i < list.size(); i++) {
                element = list.get(i);
                Log.i("list.size",list.size()+"");
                String attributevalue = element.getAttributeValue("id");  // title 태그의 속성값이 type을 찾는다
                Log.i("list.attribute",attributevalue+"");
                if (attributevalue != null) {
                    if(attributevalue.equalsIgnoreCase("sidoTable")) {
                        TextExtractor textExtractor = element.getTextExtractor();  // 해당 문자값을 가져온다
                        get_data = textExtractor.toString();  // 가져온 값을 스트링으로 변환후
                        Log.i("list.string",get_data+"");
                        array.add(get_data);  // ArrayList에 추가한다
                    }
                }
            }
        } catch (Exception e) {
        }
        return array;  // 입력된 배열값을 리턴
    }
}
어민 (180 포인트) 님이 2017년 7월 7일 질문
Log
07-07 23:47:19.771 12630-12708/? I/list.Element: [<tbody id="sidoTable">
                                                             
                                                             </tbody>]
07-07 23:47:19.771 12630-12708/? I/list.size: 1
07-07 23:47:19.781 12630-12708/kr.soen.test I/list.attribute: sidoTable
07-07 23:47:19.951 12630-12630/kr.soen.test W/art: Before Android 4.1, method int android.support.v7.widget.ListViewCompat.lookForSelectablePosition(int, boolean) would have incorrectly overridden the package-private method in android.widget.ListView
tbody안에 태그들이 많이 있는데 그것들 다 안나오고 tbody 태그만 나와요....

답변 달기

· 글에 소스 코드 보기 좋게 넣는 법
· 질문에 대해 추가적인 질문이나 의견이 있으면 답변이 아니라 댓글로 달아주시기 바랍니다.
표시할 이름 (옵션):
개인정보: 당신의 이메일은 이 알림을 보내는데만 사용됩니다.
스팸 차단 검사:
스팸 검사를 다시 받지 않으려면 로그인하거나 혹은 가입 하세요.
...