Java - HtmlUnit访问受限制的URI被拒绝

时间:2012-12-27 19:39:03

标签: java htmlunit access-denied

以下是我的代码

 WebClient webClient = new WebClient();
        HtmlPage page = webClient.getPage("http://www.cheapoair.com/");
        String pageAsText = page.asText();
        System.out.println(pageAsText);
        webClient.closeAllWindows();

当我执行它时会出现以下问题:

Caused by: net.sourceforge.htmlunit.corejs.javascript.EvaluatorException: Access to restricted URI denied (script in http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fwww.facebook.com/cheapoair&layout=button_count&show_faces=true&width=80&action=like&font=arial&colorscheme=light&height=21 from (109, 78) to (109, 2233)#109)
    at com.gargoylesoftware.htmlunit.javascript.StrictErrorReporter.runtimeError(StrictErrorReporter.java:81)
    at net.sourceforge.htmlunit.corejs.javascript.Context.reportRuntimeError(Context.java:983)
    at net.sourceforge.htmlunit.corejs.javascript.Context.reportRuntimeError(Context.java:1039)
    at com.gargoylesoftware.htmlunit.javascript.host.xml.XMLHttpRequest.open(XMLHttpRequest.java:455)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at net.sourceforge.htmlunit.corejs.javascript.MemberBox.invoke(MemberBox.java:137)
    at net.sourceforge.htmlunit.corejs.javascript.FunctionObject.call(FunctionObject.java:452)
    at net.sourceforge.htmlunit.corejs.javascript.Interpreter.interpretLoop(Interpreter.java:1473)
    at net.sourceforge.htmlunit.corejs.javascript.Interpreter.interpret(Interpreter.java:815)
    at net.sourceforge.htmlunit.corejs.javascript.InterpretedFunction.exec(InterpretedFunction.java:123)
    at com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine$3.doRun(JavaScriptEngine.java:539)
    at com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine$HtmlUnitContextAction.run(JavaScriptEngine.java:651)
    ... 90 more
Enclosed exception: 
java.lang.RuntimeException: Exception invoking setInnerHTML

1 个答案:

答案 0 :(得分:0)

我试过,它对我有用

WebClient webClient = new WebClient(BrowserVersion.INTERNET_EXPLORER_6);