我有一个资源(一个静态 html 页面),我想用它来测试。但是,当我得到静态页面时,它带有一些字符编码。我尝试使用 StringEscapeUtils 类,但它不起作用。我的功能:
private HtmlPage getStaticPage() throws IOException, ClassNotFoundException {
final Reader reader = new InputStreamReader(this.getClass().getResourceAsStream("/" + "testPage" + ".html"), "UTF-8");
final StringWebResponse response = new StringWebResponse(StringEscapeUtils.unescapeHtml4(IOUtils.toString(reader)), StandardCharsets.UTF_8, new URL(URL_PAGE));
return HTMLParser.parseHtml(response, WebClientFactory.getInstance().getCurrentWindow());
}
导入 org.apache.commons.lang3.StringEscapeUtils;