【发布时间】:2013-09-12 15:03:33
【问题描述】:
我尝试使用 HtmlUnit(2.12 版)登录我的大学网站,但我遇到了与网站编码相关的问题
代码:
try {
WebClient webClient = new WebClient(BrowserVersion.INTERNET_EXPLORER_9);
WebClientOptions options = webClient.getOptions();
options.setCssEnabled(false);
options.setThrowExceptionOnScriptError(false);
options.setThrowExceptionOnFailingStatusCode(false);
options.setRedirectEnabled(true);
options.setJavaScriptEnabled(true);
HtmlPage page = (HtmlPage) webClient.getPage("http://www.oid.hacettepe.edu.tr/cgi-bin/menuindex.cgi");
} catch (IOException ex) {
Logger.getLogger(AnaSayfa.class.getName()).log(Level.SEVERE, null, ex);
} catch (FailingHttpStatusCodeException ex) {
Logger.getLogger(AnaSayfa.class.getName()).log(Level.SEVERE, null, ex);
}
例外:
java.io.UnsupportedEncodingException: İSO-8859-9
我也尝试使用此代码更改字符集:
WebRequest webRequest = new WebRequest(new URL("http://www.oid.hacettepe.edu.tr/cgi-bin/menuindex.cgi"));
webRequest.setCharset("utf-8");
HtmlPage page = (HtmlPage) webClient.getPage(webRequest);
但我的问题还在继续:(请给出解决方案的任何建议
【问题讨论】: