import java.io.*;
import java.net.URL;
import java.net.URLConnection;
import javax.swing.text.html.*;
import javax.swing.text.html.HTML.*;
import javax.swing.text.html.HTMLDocument;
import javax.swing.text.AttributeSet;
import javax.swing.text.Element;
import javax.swing.text.ElementIterator;
import javax.swing.text.StyleConstants;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import javax.swing.text.BadLocationException;
import javax.swing.text.MutableAttributeSet;
import javax.swing.text.html.parser.ParserDelegator;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class TestHtmlParse {
public static void main(String[] args) {
HttpURLConnection httpConn = null;
String urlParameters=""; //파라메타값
String targetURL="http://www.nts.go.kr/cal/cal_check_02_01.asp?Source_Saup_No_2_2_9=2141154606&Target_Saup_No_2_2_9=1321765142";
try{
URL url = new URL(targetURL);
httpConn = (HttpURLConnection)url.openConnection();
//헤더 선언
httpConn.setRequestMethod("POST");
httpConn.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
//httpConn.setRequestProperty("Content-Type", "application/x-www-form-urlencoded;charset=EUC-KR");
// httpConn.setRequestProperty("Cookie", "cookievalue="+ cookie);
httpConn.setUseCaches (false);
httpConn.setDoInput(true);
httpConn.setDoOutput(true);
PrintWriter pw = new PrintWriter(new OutputStreamWriter(httpConn.getOutputStream()));
//PrintWriter pw = new PrintWriter(new OutputStreamWriter(httpConn.getOutputStream(), "EUC-KR"));
pw.write(urlParameters);
pw.flush();
pw.close();
// OutputStream opstrm = httpConn.getOutputStream();
// opstrm.write(param.getBytes());
// opstrm.flush();
// opstrm.close();
String line = null;
BufferedReader in = new BufferedReader(new InputStreamReader(httpConn.getInputStream(), "euc-kr"));
while ((line = in.readLine()) != null) {
//<b style="color:blue">부가가치세 일반과세자</b>
Pattern pattern = Pattern.compile("<b[^*]style=\"color:blue\">*");
Matcher m = pattern.matcher(line.trim());
String special_str = "";
while (m.find()) {
special_str = m.group();
System.out.println(line);
System.out.println(special_str);
}
}
in.close();
} catch (IOException ioe) {
ioe.printStackTrace();
}
}
}
Expression Language (0) | 2014.12.10 |
---|---|
JSTL (0) | 2014.12.10 |
java document를 chm 파일로 다운로드 (0) | 2014.06.10 |
java에서 sftp 연결하기 (0) | 2014.06.10 |
MSSQL jdbc - sqljdbc.jar와 sqljdbc4.jar 차이 (0) | 2013.03.19 |