import java.io.IOException;
import java.io.InputStreamReader;
import java.io.Reader;
import java.io.StringWriter;
import java.net.URL;
import java.net.URLConnection;
import javax.swing.text.BadLocationException;
import javax.swing.text.Document;
import javax.swing.text.EditorKit;
import javax.swing.text.html.HTMLEditorKit;
public class Parsing_Main {
public static void main(String args[]) throws IOException {
EditorKit kit = new HTMLEditorKit();
Document doc = kit.createDefaultDocument();
doc.putProperty("IgnoreCharsetDirective", Boolean.TRUE);
URLConnection conn = new URL("파싱웹주소").openConnection();
Reader rd = new InputStreamReader(conn.getInputStream());
String str = "";
try {
/* doc에 웹 내용을 저장(html태그는 자동 삭제되어 저장 */
kit.read(rd, doc, 0);
// str = doc.getText(0, doc.getLength());
} catch (BadLocationException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
StringWriter writer = new StringWriter();
String str2 = "";
try {
/* doc에 저장된 내용을 html태그를 붙여서 writer에 저장 */
kit.write(writer, doc, 0, doc.getLength());
str2 = writer.toString();
} catch (BadLocationException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
System.out.println(str2);
}
}
댓글 없음 :
댓글 쓰기