HTMLunit – Facebook登录

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=[] 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);