HTMLunit - 脸书登入

HTMLunit - Facebook Login

final WebClient webClient = new WebClient();
    webClient.setJavaScriptEngine(new JavaScriptEngine(webClient));
    HtmlPage page1 = null;
    try {
        page1 = webClient.getPage("http://www.facebook.com");
    } catch (IOException e) {
        e.printStackTrace();
    }
    final HtmlForm form = (HtmlForm) page1.getElementById("login_form");

    final HtmlSubmitInput button = (HtmlSubmitInput) form.getInputsByValue("Log In").get(0);
    final HtmlTextInput textField = (HtmlTextInput) page1.getElementById("email");
    textField.setValueAttribute("test@test.com");
    final HtmlPasswordInput textField2 = (HtmlPasswordInput) page1.getElementById("pass");
    textField2.setValueAttribute("password1");
    try {
        HtmlPage page2 = button.click();
        System.out.println(page2.getTitleText());

    } catch (IOException e) {
        e.printStackTrace();
    }

我正在尝试使用 HTMLUnit 登录 facebook 上的帐户。但是我收到此错误:

我正在寻找一个程序来自动执行我在 Facebook 上的网页所做的一些事情。我知道这样的东西可能已经存在,但我只是为了好玩。

======= EXCEPTION START ========


EcmaError: lineNumber=[97] column=[0] lineSource=[<no source>] name=[TypeError] sourceName=[https://fbstatic-a.akamaihd.net/rsrc.php/v2/y8/r/ElsISGBmlSN.js] message=[TypeError: Cannot find function addImport in object [object CSSStyleSheet]. (https://fbstatic-a.akamaihd.net/rsrc.php/v2/y8/r/ElsISGBmlSN.js#97)]
com.gargoylesoftware.htmlunit.ScriptException: TypeError: Cannot find function addImport in object [object CSSStyleSheet]. (https://fbstatic-a.akamaihd.net/rsrc.php/v2/y8/r/ElsISGBmlSN.js#97)

当我将 BrowserVersion 添加到 WebClient 构造函数时,我不再收到此错误:

 final WebClient webClient = new WebClient(BrowserVersion.FIREFOX_38);