所以,我是Java新手,这是我的第一个程序。我正在使用HtmlUnit和Mars工作Java Eclipse,我相信我的Eclipse
这是我目前使用的代码
public static void webstart(String website) throws InterruptedException
{
try (WebClient webClient = new WebClient(BrowserVersion.getDefault()))
{
label1.setText("Status: Loading Light Viewer...");
HtmlPage page = webClient.getPage(website);
label1.setText("Status: Clicking Start Viewer...");
HtmlElement start = (HtmlElement) page.getByXPath("//*[@id='main_page_offline']/div/div[3]/div/div/a");
start.click();
label1.setText("Status: Clicked...");
i=2;
while(i==2)
{
HtmlElement text = (HtmlElement) page.getByXPath("//*[@id='visio_compteur']");
String time = text.toString();
timer(time);
}
}
catch (FailingHttpStatusCodeException e)
{
e.printStackTrace();
}
catch (MalformedURLException e)
{
e.printStackTrace();
}
catch (IOException e)
{
e.printStackTrace();
} finally {
}
}
将Loading Light Viewer ...写入标签后崩溃了。
以下是我目前正在犯的错误
Exception class=[net.sourceforge.htmlunit.corejs.javascript.EvaluatorException]
com.gargoylesoftware.htmlunit.ScriptException: syntax error (script in www.websitehere.com from (289, 32) to (291, 10)#290)
at com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine$HtmlUnitContextAction.run(JavaScriptEngine.java:865)
at net.sourceforge.htmlunit.corejs.javascript.Context.call(Context.java:628)
at net.sourceforge.htmlunit.corejs.javascript.ContextFactory.call(ContextFactory.java:513)
at com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine.compile(JavaScriptEngine.java:701)
at com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine.execute(JavaScriptEngine.java:718)
at com.gargoylesoftware.htmlunit.html.HtmlPage.executeJavaScriptIfPossible(HtmlPage.java:945)
at com.gargoylesoftware.htmlunit.html.HtmlScript.executeInlineScriptIfNeeded(HtmlScript.java:351)
at com.gargoylesoftware.htmlunit.html.HtmlScript.executeScriptIfNeeded(HtmlScript.java:411)
at com.gargoylesoftware.htmlunit.html.HtmlScript$3.execute(HtmlScript.java:270)
at com.gargoylesoftware.htmlunit.html.HtmlScript.onAllChildrenAddedToPage(HtmlScript.java:290)
at com.gargoylesoftware.htmlunit.html.HTMLParser$HtmlUnitDOMBuilder.endElement(HTMLParser.java:800)
at org.apache.xerces.parsers.AbstractSAXParser.endElement(Unknown Source)
at com.gargoylesoftware.htmlunit.html.HTMLParser$HtmlUnitDOMBuilder.endElement(HTMLParser.java:757)
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:3126)
at org.cyberneko.html.HTMLScanner$ContentScanner.scan(HTMLScanner.java:2093)
at org.cyberneko.html.HTMLScanner.scanDocument(HTMLScanner.java:920)
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:1040)
at com.gargoylesoftware.htmlunit.html.HTMLParser.parse(HTMLParser.java:253)
at com.gargoylesoftware.htmlunit.html.HTMLParser.parseHtml(HTMLParser.java:199)
at com.gargoylesoftware.htmlunit.DefaultPageCreator.createHtmlPage(DefaultPageCreator.java:272)
at com.gargoylesoftware.htmlunit.DefaultPageCreator.createPage(DefaultPageCreator.java:160)
at com.gargoylesoftware.htmlunit.WebClient.loadWebResponseInto(WebClient.java:476)
at com.gargoylesoftware.htmlunit.WebClient.getPage(WebClient.java:350)
at com.gargoylesoftware.htmlunit.WebClient.getPage(WebClient.java:415)
at com.gargoylesoftware.htmlunit.WebClient.getPage(WebClient.java:400)
at websync.websyn.webstart(websyn.java:110)
at websync.websyn$1.widgetSelected(websyn.java:86)
at org.eclipse.swt.widgets.TypedListener.handleEvent(TypedListener.java:248)
at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:84)
at org.eclipse.swt.widgets.Display.sendEvent(Display.java:4362)
at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1113)
at org.eclipse.swt.widgets.Display.runDeferredEvents(Display.java:4180)
at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3769)
at websync.websyn.open(websyn.java:56)
at websync.websyn.main(websyn.java:40)
Caused by: net.sourceforge.htmlunit.corejs.javascript.EvaluatorException: syntax error (script in www.websitehere.com/ from (289, 32) to (291, 10)#290)
at com.gargoylesoftware.htmlunit.javascript.StrictErrorReporter.error(StrictErrorReporter.java:66)
at net.sourceforge.htmlunit.corejs.javascript.Parser.addError(Parser.java:187)
at net.sourceforge.htmlunit.corejs.javascript.Parser.addError(Parser.java:167)
at net.sourceforge.htmlunit.corejs.javascript.Parser.reportError(Parser.java:254)
at net.sourceforge.htmlunit.corejs.javascript.Parser.reportError(Parser.java:243)
at net.sourceforge.htmlunit.corejs.javascript.Parser.reportError(Parser.java:236)
at net.sourceforge.htmlunit.corejs.javascript.Parser.primaryExpr(Parser.java:2816)
at net.sourceforge.htmlunit.corejs.javascript.Parser.memberExpr(Parser.java:2388)
at net.sourceforge.htmlunit.corejs.javascript.Parser.unaryExpr(Parser.java:2292)
at net.sourceforge.htmlunit.corejs.javascript.Parser.mulExpr(Parser.java:2219)
at net.sourceforge.htmlunit.corejs.javascript.Parser.addExpr(Parser.java:2205)
at net.sourceforge.htmlunit.corejs.javascript.Parser.shiftExpr(Parser.java:2188)
at net.sourceforge.htmlunit.corejs.javascript.Parser.relExpr(Parser.java:2165)
at net.sourceforge.htmlunit.corejs.javascript.Parser.eqExpr(Parser.java:2139)
at net.sourceforge.htmlunit.corejs.javascript.Parser.bitAndExpr(Parser.java:2130)
at net.sourceforge.htmlunit.corejs.javascript.Parser.bitXorExpr(Parser.java:2121)
at net.sourceforge.htmlunit.corejs.javascript.Parser.bitOrExpr(Parser.java:2112)
at net.sourceforge.htmlunit.corejs.javascript.Parser.andExpr(Parser.java:2103)
at net.sourceforge.htmlunit.corejs.javascript.Parser.orExpr(Parser.java:2094)
at net.sourceforge.htmlunit.corejs.javascript.Parser.condExpr(Parser.java:2060)
at net.sourceforge.htmlunit.corejs.javascript.Parser.assignExpr(Parser.java:2033)
at net.sourceforge.htmlunit.corejs.javascript.Parser.variables(Parser.java:1878)
at net.sourceforge.htmlunit.corejs.javascript.Parser.statementHelper(Parser.java:1009)
at net.sourceforge.htmlunit.corejs.javascript.Parser.statement(Parser.java:926)
at net.sourceforge.htmlunit.corejs.javascript.Parser.parse(Parser.java:570)
at net.sourceforge.htmlunit.corejs.javascript.Parser.parse(Parser.java:491)
at net.sourceforge.htmlunit.corejs.javascript.Context.compileImpl(Context.java:2661)
at net.sourceforge.htmlunit.corejs.javascript.Context.compileString(Context.java:1624)
at com.gargoylesoftware.htmlunit.javascript.HtmlUnitContextFactory$TimeoutContext.compileString(HtmlUnitContextFactory.java:202)
at net.sourceforge.htmlunit.corejs.javascript.Context.compileString(Context.java:1616)
at com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine$2.doRun(JavaScriptEngine.java:692)
at com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine$HtmlUnitContextAction.run(JavaScriptEngine.java:850)
... 41 more
Enclosed exception:
net.sourceforge.htmlunit.corejs.javascript.EvaluatorException: syntax error (script in www.websitehere.com/ from (289, 32) to (291, 10)#290)
at com.gargoylesoftware.htmlunit.javascript.StrictErrorReporter.error(StrictErrorReporter.java:66)
at net.sourceforge.htmlunit.corejs.javascript.Parser.addError(Parser.java:187)
at net.sourceforge.htmlunit.corejs.javascript.Parser.addError(Parser.java:167)
at net.sourceforge.htmlunit.corejs.javascript.Parser.reportError(Parser.java:254)
at net.sourceforge.htmlunit.corejs.javascript.Parser.reportError(Parser.java:243)
at net.sourceforge.htmlunit.corejs.javascript.Parser.reportError(Parser.java:236)
at net.sourceforge.htmlunit.corejs.javascript.Parser.primaryExpr(Parser.java:2816)
at net.sourceforge.htmlunit.corejs.javascript.Parser.memberExpr(Parser.java:2388)
at net.sourceforge.htmlunit.corejs.javascript.Parser.unaryExpr(Parser.java:2292)
at net.sourceforge.htmlunit.corejs.javascript.Parser.mulExpr(Parser.java:2219)
at net.sourceforge.htmlunit.corejs.javascript.Parser.addExpr(Parser.java:2205)
at net.sourceforge.htmlunit.corejs.javascript.Parser.shiftExpr(Parser.java:2188)
at net.sourceforge.htmlunit.corejs.javascript.Parser.relExpr(Parser.java:2165)
at net.sourceforge.htmlunit.corejs.javascript.Parser.eqExpr(Parser.java:2139)
at net.sourceforge.htmlunit.corejs.javascript.Parser.bitAndExpr(Parser.java:2130)
at net.sourceforge.htmlunit.corejs.javascript.Parser.bitXorExpr(Parser.java:2121)
at net.sourceforge.htmlunit.corejs.javascript.Parser.bitOrExpr(Parser.java:2112)
at net.sourceforge.htmlunit.corejs.javascript.Parser.andExpr(Parser.java:2103)
at net.sourceforge.htmlunit.corejs.javascript.Parser.orExpr(Parser.java:2094)
at net.sourceforge.htmlunit.corejs.javascript.Parser.condExpr(Parser.java:2060)
at net.sourceforge.htmlunit.corejs.javascript.Parser.assignExpr(Parser.java:2033)
at net.sourceforge.htmlunit.corejs.javascript.Parser.variables(Parser.java:1878)
at net.sourceforge.htmlunit.corejs.javascript.Parser.statementHelper(Parser.java:1009)
at net.sourceforge.htmlunit.corejs.javascript.Parser.statement(Parser.java:926)
at net.sourceforge.htmlunit.corejs.javascript.Parser.parse(Parser.java:570)
at net.sourceforge.htmlunit.corejs.javascript.Parser.parse(Parser.java:491)
at net.sourceforge.htmlunit.corejs.javascript.Context.compileImpl(Context.java:2661)
at net.sourceforge.htmlunit.corejs.javascript.Context.compileString(Context.java:1624)
at com.gargoylesoftware.htmlunit.javascript.HtmlUnitContextFactory$TimeoutContext.compileString(HtmlUnitContextFactory.java:202)
at net.sourceforge.htmlunit.corejs.javascript.Context.compileString(Context.java:1616)
at com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine$2.doRun(JavaScriptEngine.java:692)
at com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine$HtmlUnitContextAction.run(JavaScriptEngine.java:850)
at net.sourceforge.htmlunit.corejs.javascript.Context.call(Context.java:628)
at net.sourceforge.htmlunit.corejs.javascript.ContextFactory.call(ContextFactory.java:513)
at com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine.compile(JavaScriptEngine.java:701)
at com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine.execute(JavaScriptEngine.java:718)
at com.gargoylesoftware.htmlunit.html.HtmlPage.executeJavaScriptIfPossible(HtmlPage.java:945)
at com.gargoylesoftware.htmlunit.html.HtmlScript.executeInlineScriptIfNeeded(HtmlScript.java:351)
at com.gargoylesoftware.htmlunit.html.HtmlScript.executeScriptIfNeeded(HtmlScript.java:411)
at com.gargoylesoftware.htmlunit.html.HtmlScript$3.execute(HtmlScript.java:270)
at com.gargoylesoftware.htmlunit.html.HtmlScript.onAllChildrenAddedToPage(HtmlScript.java:290)
at com.gargoylesoftware.htmlunit.html.HTMLParser$HtmlUnitDOMBuilder.endElement(HTMLParser.java:800)
at org.apache.xerces.parsers.AbstractSAXParser.endElement(Unknown Source)
at com.gargoylesoftware.htmlunit.html.HTMLParser$HtmlUnitDOMBuilder.endElement(HTMLParser.java:757)
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:3126)
at org.cyberneko.html.HTMLScanner$ContentScanner.scan(HTMLScanner.java:2093)
at org.cyberneko.html.HTMLScanner.scanDocument(HTMLScanner.java:920)
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:1040)
at com.gargoylesoftware.htmlunit.html.HTMLParser.parse(HTMLParser.java:253)
at com.gargoylesoftware.htmlunit.html.HTMLParser.parseHtml(HTMLParser.java:199)
at com.gargoylesoftware.htmlunit.DefaultPageCreator.createHtmlPage(DefaultPageCreator.java:272)
at com.gargoylesoftware.htmlunit.DefaultPageCreator.createPage(DefaultPageCreator.java:160)
at com.gargoylesoftware.htmlunit.WebClient.loadWebResponseInto(WebClient.java:476)
at com.gargoylesoftware.htmlunit.WebClient.getPage(WebClient.java:350)
at com.gargoylesoftware.htmlunit.WebClient.getPage(WebClient.java:415)
at com.gargoylesoftware.htmlunit.WebClient.getPage(WebClient.java:400)
at websync.websyn.webstart(websyn.java:110)
at websync.websyn$1.widgetSelected(websyn.java:86)
at org.eclipse.swt.widgets.TypedListener.handleEvent(TypedListener.java:248)
at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:84)
at org.eclipse.swt.widgets.Display.sendEvent(Display.java:4362)
at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1113)
at org.eclipse.swt.widgets.Display.runDeferredEvents(Display.java:4180)
at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3769)
at websync.websyn.open(websyn.java:56)
at websync.websyn.main(websyn.java:40)
== CALLING JAVASCRIPT ==
var add_target=;
答案 0 :(得分:1)
在网站的JavaScript中看起来像是一个错误。
Haven你没试过这个设置吗?
webClient.getOptions().setThrowExceptionOnScriptError(false);
前
HtmlPage page = webClient.getPage(website);