안녕하세요.
금일도 수고가 많으십니다.
html 파싱 쪽으로 여쭤보려구요
부득이하게 생 html을 파싱하고 있습니다.
제가 HtmlCleaner 이용해서 html에서 제가 사용하려 하는
<a href > 태그의 주소와 태그 사이의 description 값을 가져 오려고 합니다.
HtmlCleaner cleaner=new HtmlCleaner();
CleanerProperties props=cleaner.getProperties();
props.setOmitComments(true); // 주석제거
props.setOmitDeprecatedTags(true);
props.setOmitUnknownTags(true);
Writer str = new StringWriter();
TagNode node=null;
TagNode[] myNodes=null;
TagNode testnode=null;
try {
node=cleaner.clean(strHtml);
myNodes = node.getElementsByName("a", true);
for(Object on : myNodes)
{
TagNode n = (TagNode) on;
String strUrl = n.getAttributeByName("href");
String strUrlDes;
strUrlDes = n.getText().toString();
System.out.println("\thref="+n.getAttributeByName("href")+", text="+n.getText());
byte[] buff = new byte[1280];
strUrl.getBytes(1, strUrl.getBytes().length, buff, 1);
strUrl = "주소" + EncodingUtils.getString(buff, 1, buff.length-1, "euc-kr");
list_NewsUrl.add(strUrl);
list_NewsUrlDes.add(strUrlDes);
}
}
catch (IOException e) {
e.printStackTrace();
}
위와 같이 하면 에물에서 제가 원하는 a href 의 url 값과 태그 사이의 텍스트 값을 가져 올수가 있는데요.
이상하게 폰에 올려서 하면 myNodes에 아무 값도 들어오지 못하고 count 가 0이 나옵니다.
그래서 원하는 정보를 파싱 할수 없습니다.
문제는 a href 태그에 name 이나 id가 없다는 겂니다.. 다른 방법이 있으면 좀 조언 부탁드립니다.