미세먼지 값을 받아오려고 하는데 하루죙일 해도 안되네요
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; // 입력된 배열값을 리턴
}
}