我安装了HtmlUnit并编写了简单的测试程序,以检查一切是否正常。 所以,这是我使用HtmlUnit的非常简单的测试程序:
public class Main {
public static void main(String[] args) throws Exception {
WebClient webClient = new WebClient();
HtmlPage page = webClient.getPage("http://htmlunit.sourceforge.net");
webClient.close();
}
}
当我尝试运行它时,我明白了:
Exception in thread "main" java.lang.NoSuchFieldError: INSTANCE
at org.apache.http.conn.ssl.SSLConnectionSocketFactory.<clinit>(SSLConnectionSocketFactory.java:144)
at com.gargoylesoftware.htmlunit.HttpWebConnection.configureHttpsScheme(HttpWebConnection.java:597)
at com.gargoylesoftware.htmlunit.HttpWebConnection.createHttpClient(HttpWebConnection.java:532)
at com.gargoylesoftware.htmlunit.HttpWebConnection.getHttpClientBuilder(HttpWebConnection.java:494)
at com.gargoylesoftware.htmlunit.HttpWebConnection.getResponse(HttpWebConnection.java:158)
at com.gargoylesoftware.htmlunit.WebClient.loadWebResponseFromWebConnection(WebClient.java:1321)
at com.gargoylesoftware.htmlunit.WebClient.loadWebResponse(WebClient.java:1238)
at com.gargoylesoftware.htmlunit.WebClient.getPage(WebClient.java:346)
at com.gargoylesoftware.htmlunit.WebClient.getPage(WebClient.java:415)
at com.gargoylesoftware.htmlunit.WebClient.getPage(WebClient.java:400)
at code.elix_x.programs.nfixer.Main.main(Main.java:10)
这与我试图获得的页面无关。 我无法在任何地方找到修复错误的方法。 这可能是由他们安装的其他API引起的(除了HtmlUnit,我有google apis,gson api,jsoup api和那些必需的API)?
感谢您的帮助!
答案 0 :(得分:0)
您需要为WebClient构造函数指定浏览器,否则您将无法连接到该页面:
WebClient webClient = new WebClient(BrowserVersion.CHROME);