WebClient 无法加载推特页面

WebClient cant load twitter page

这是我的代码。我尝试在 Java.

中使用 WebClient 加载 Twitter 注册页面
public LoadTwitter() {
    client = new WebClient(BrowserVersion.CHROME);
    client.getOptions().setJavaScriptEnabled(true);
    client.getOptions().setThrowExceptionOnScriptError(false);
    //client.waitForBackgroundJavaScript(2000);
}

public void loadPage() throws IOException {
    HtmlPage page = client.getPage("http://twitter.com/signup");
}

但是我有很多 javascript 错误。如果我关闭 javascript。我得到移动版本而不是网络。如何解决这个问题?

янв 24, 2016 6:50:27 PM com.gargoylesoftware.htmlunit.IncorrectnessListenerImpl notify
WARNING: Obsolete content type encountered: 'text/javascript'.
янв 24, 2016 6:50:27 PM com.gargoylesoftware.htmlunit.IncorrectnessListenerImpl notify
WARNING: Obsolete content type encountered: 'text/javascript'.
янв 24, 2016 6:50:28 PM com.gargoylesoftware.htmlunit.IncorrectnessListenerImpl notify
WARNING: Obsolete content type encountered: 'text/javascript'.
янв 24, 2016 6:50:29 PM com.gargoylesoftware.htmlunit.javascript.host.css.CSSStyleSheet isValidSelector
WARNING: Unhandled CSS condition type '7'. Accepting it silently.
янв 24, 2016 6:50:29 PM com.gargoylesoftware.htmlunit.javascript.StrictErrorReporter runtimeError
SEVERE: runtimeError: message=[An invalid or illegal selector was specified (selector: '*,:x' error: Invalid selector: *:x).] sourceName=[https://abs.twimg.com/c/swift/en/init.c624198d27d7d00677cf16d484b32903b375bbc6.js] line=[108] lineSource=[null] lineOffset=[0]
янв 24, 2016 6:50:32 PM com.gargoylesoftware.htmlunit.DefaultCssErrorHandler error
======= EXCEPTION START ========
EcmaError: lineNumber=[8] column=[0] lineSource=[null] name=[TypeError] sourceName=[https://abs.twimg.com/c/swift/en/bundle/signup.5fb6bc11a86475b13235f34876f4d57d28669252.js] message=[TypeError: Cannot call method "call" of undefined (https://abs.twimg.com/c/swift/en/bundle/signup.5fb6bc11a86475b13235f34876f4d57d28669252.js#8)]
com.gargoylesoftware.htmlunit.ScriptException: TypeError: Cannot call method "call" of undefined (https://abs.twimg.com/c/swift/en/bundle/signup.5fb6bc11a86475b13235f34876f4d57d28669252.js#8)
    at com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine$HtmlUnitContextAction.run(JavaScriptEngine.java:865)
== CALLING JAVASCRIPT ==
  function (b) {
      b = a.event || b;
      if (b.type == "load" || w(["loaded", "complete"], this.readyState) > -1) {
          this.onreadystatechange = null;
          c.loaded();
      }
  }
======= EXCEPTION END ========

试试这个,它应该通过 HtmlUnit 删除日志:

LogFactory.getFactory().setAttribute("org.apache.commons.logging.Log", "org.apache.commons.logging.impl.NoOpLog");

java.util.logging.Logger.getLogger("com.gargoylesoftware").setLevel(Level.OFF); 
java.util.logging.Logger.getLogger("org.apache.commons.httpclient").setLevel(Level.OFF);

client = new WebClient(BrowserVersion.CHROME);
client.getOptions().setJavaScriptEnabled(true);
client.getOptions().setThrowExceptionOnScriptError(false);
client.getOptions().setThrowExceptionOnFailingStatusCode(false);