안드로이드 개발 질문/답변
(글 수 45,052)
html소스에서
<ul id="hs_notice">
<table width=100% border=0 cellpadding=0 cellspacing=0 >
<tr height="30">
<td height=20 bgcolor=white align=center width="5%">
<a href=read.php?id=11&no=0&field=&search_word=>11</a>
</td>
<!-- 번호 끝 -->
<!-- 제목 -->
<td height=20 bgcolor=white >
<a href=read.php?id=11&no=0&field=&search_word=>
안녕하세요</a>
</td>
번호랑 제목(빨강)만 뽑아와서 리스트뷰에 빼내 오고 싶은데요.. 가능한가요??
jericho 파서 쓰니까 그냥 전부 가져오더라구요..
저렇게 필요한 부분만 가져오려면 어떡해야 되나요?
<a href=read.php?id=11&no=0&field=&search_word=>이부분이 반복되는거 같은데
어떤 방법을 쓰면 좋을까요? 고수님들 조언부탁드립니다^^
<ul id="hs_notice">
<table width=100% border=0 cellpadding=0 cellspacing=0 >
<tr height="30">
<td height=20 bgcolor=white align=center width="5%">
<a href=read.php?id=11&no=0&field=&search_word=>11</a>
</td>
<!-- 번호 끝 -->
<!-- 제목 -->
<td height=20 bgcolor=white >
<a href=read.php?id=11&no=0&field=&search_word=>
안녕하세요</a>
</td>
번호랑 제목(빨강)만 뽑아와서 리스트뷰에 빼내 오고 싶은데요.. 가능한가요??
jericho 파서 쓰니까 그냥 전부 가져오더라구요..
저렇게 필요한 부분만 가져오려면 어떡해야 되나요?
<a href=read.php?id=11&no=0&field=&search_word=>이부분이 반복되는거 같은데
어떤 방법을 쓰면 좋을까요? 고수님들 조언부탁드립니다^^
2010.10.11 10:06:05
저같은 경우에는 HTML문장을 무식하게 받아 왔는데요..
String html = DownloadHtml(str); 일단 HTML 소스를 가지고 와서 String 변수에 저장 하시구요..
다음으로.. 그 문장의 시작과 끝의 인덱스 번호를 가지고 와야 합니다..
int index_sta = html.indexOf("pad_top50 -->");
int index_end = html.indexOf("<!-- 3단락 -->");
이런식으로 말이죠.. 이렇게 가지고 오면 index_sta에는 p 의 인덱스 값이 저장되고 index_end에는 < 의 값이 저장 됩니다..
이렇게 받아 오셔서 html = html.substring(index_sta + 13, index_end); 이렇게 사용 하시면 가지고 오게 됩니다..
여기서 index_sta + 13 의 +13은 pad_top50 --> 의 끝부분부터 읽어 와야 하기 때문에 +13을 해 준거구요...
HTML 파싱방법은 많습니다... 충분하게 찾아 보시구요... 말씀 드리는거지만 제가 알려드린 방법은.....
노가다 많이 심함니다......... 참고 하세요....
2010.10.11 10:34:27
ㄴ 답변 감사합니다!^^
정말 노가다가 필요하겠군요..
HtmlCleaner를 이용해보고있는데요..
예제를 이용해서..(참고로 빼올부분은 번호의 11하고 제목의 안녕하세요 입니다)
TextView tv = (TextView) findViewById(R.id.TextView01);
HtmlCleaner cleaner = new HtmlCleaner();
CleanerProperties props = cleaner.getProperties();
props.setOmitComments(true); //주석제거
try{
TagNode node = cleaner.clean(Url);
Object[] objArray = node.evaluateXPath("//table//tr//td//a[@href=read.php?id=12&no=0&field=&search_word=]");
for (Object obj: objArray) {
TagNode t = (TagNode)obj;
tv.setText(t.getText().toString());
}
}catch(IOException e ){
e.printStackTrace();
}catch (XPatherException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
요래 해봤는데 텍스트뷰에 안나오네요..
소스의 어디가 잘못된걸까요..?ㅠ.ㅠ
정말 노가다가 필요하겠군요..
HtmlCleaner를 이용해보고있는데요..
예제를 이용해서..(참고로 빼올부분은 번호의 11하고 제목의 안녕하세요 입니다)
TextView tv = (TextView) findViewById(R.id.TextView01);
HtmlCleaner cleaner = new HtmlCleaner();
CleanerProperties props = cleaner.getProperties();
props.setOmitComments(true); //주석제거
try{
TagNode node = cleaner.clean(Url);
Object[] objArray = node.evaluateXPath("//table//tr//td//a[@href=read.php?id=12&no=0&field=&search_word=]");
for (Object obj: objArray) {
TagNode t = (TagNode)obj;
tv.setText(t.getText().toString());
}
}catch(IOException e ){
e.printStackTrace();
}catch (XPatherException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
요래 해봤는데 텍스트뷰에 안나오네요..
소스의 어디가 잘못된걸까요..?ㅠ.ㅠ