gpt4 book ai didi

java - 使用 HtmlUnit WebClient.getPage 时出现多个错误

转载 作者:太空宇宙 更新时间:2023-11-04 11:53:52 27 4
gpt4 key购买 nike

我是第一次尝试 HtmlUnit。我正在 Linux Mint 17.1 上进行开发。我也是 Java 新手。我安装了jenkins-htmlunit,我的java环境是java-7-openjdk-amd64。

我找到了以下示例:

import com.gargoylesoftware.htmlunit.WebClient;
import com.gargoylesoftware.htmlunit.html.HtmlPage;

public class myClient {
public static void main(String[] args) throws Exception {
WebClient webClient = new WebClient();
HtmlPage page = webClient.getPage("http://htmlunit.sourceforge.net");
System.out.println(page.asXml());
}
}

但是,执行以下 shell 命令后:

javac -cp "/usr/share/java/" myClient.java export CLASSPATH=$CLASSPATH:/usr/share/java/ java myClient

我收到以下错误:

Exception in thread "main" java.lang.NullPointerException at com.gargoylesoftware.htmlunit.javascript.SimpleScriptable.getPrototype(SimpleScriptable.java:247) at com.gargoylesoftware.htmlunit.javascript.SimpleScriptable.makeScriptableFor(SimpleScriptable.java:217) at com.gargoylesoftware.htmlunit.html.DomNode.getScriptObject(DomNode.java:790) at com.gargoylesoftware.htmlunit.html.HtmlScript.setAndExecuteReadyState(HtmlScript.java:457) at com.gargoylesoftware.htmlunit.html.HtmlScript$1.execute(HtmlScript.java:212) at com.gargoylesoftware.htmlunit.html.HtmlScript.onAllChildrenAddedToPage(HtmlScript.java:238) at com.gargoylesoftware.htmlunit.html.HTMLParser$HtmlUnitDOMBuilder.endElement(HTMLParser.java:699) at org.apache.xerces.parsers.AbstractSAXParser.endElement(Unknown Source) at com.gargoylesoftware.htmlunit.html.HTMLParser$HtmlUnitDOMBuilder.endElement(HTMLParser.java:657) at org.cyberneko.html.HTMLTagBalancer.callEndElement(HTMLTagBalancer.java:1170) at org.cyberneko.html.HTMLTagBalancer.endElement(HTMLTagBalancer.java:1072) at org.cyberneko.html.filters.DefaultFilter.endElement(DefaultFilter.java:206) at org.cyberneko.html.filters.NamespaceBinder.endElement(NamespaceBinder.java:330) at org.cyberneko.html.HTMLScanner$ContentScanner.scanEndElement(HTMLScanner.java:3116) at org.cyberneko.html.HTMLScanner$ContentScanner.scan(HTMLScanner.java:2083) at org.cyberneko.html.HTMLScanner.scanDocument(HTMLScanner.java:918) at org.cyberneko.html.HTMLConfiguration.parse(HTMLConfiguration.java:499) at org.cyberneko.html.HTMLConfiguration.parse(HTMLConfiguration.java:452) at org.apache.xerces.parsers.XMLParser.parse(Unknown Source) at com.gargoylesoftware.htmlunit.html.HTMLParser$HtmlUnitDOMBuilder.parse(HTMLParser.java:901) at com.gargoylesoftware.htmlunit.html.HTMLParser.parse(HTMLParser.java:350) at com.gargoylesoftware.htmlunit.html.HTMLParser.parseHtml(HTMLParser.java:304) at com.gargoylesoftware.htmlunit.DefaultPageCreator.createHtmlPage(DefaultPageCreator.java:134) at com.gargoylesoftware.htmlunit.DefaultPageCreator.createPage(DefaultPageCreator.java:101) at com.gargoylesoftware.htmlunit.WebClient.loadWebResponseInto(WebClient.java:449) at com.gargoylesoftware.htmlunit.WebClient.getPage(WebClient.java:332) at com.gargoylesoftware.htmlunit.WebClient.getPage(WebClient.java:389) at com.gargoylesoftware.htmlunit.WebClient.getPage(WebClient.java:374) at myClient.main(myClient.java:8)

最佳答案

当我使用最新的快照版本时,这对我来说效果很好。请切换到最新的快照(此页面http://htmlunit.sourceforge.net/gettingLatestCode.html上有一些有用的详细信息)。如果您没有特殊需求,那么使用最新的快照版本始终是一个好主意,因为我们正在根据用户反馈进行定期修复。

关于java - 使用 HtmlUnit WebClient.getPage 时出现多个错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41532425/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com