3

この質問は、この質問への追加です: Java を使用してプログラムで Facebook にログインする方法は?

次のコード (のわずかに変更されたバージョン) を使用して、他の Web サイトのアカウントに問題なくログインしました。

WebClient webClient = new WebClient();
HtmlPage page1 = webClient.getPage("http://www.facebook.com");
HtmlForm form = page1.getForms().get(0);
HtmlSubmitInput button = (HtmlSubmitInput) form.getInputsByValue("Login").get(0);
HtmlTextInput textField = form.getInputByName("email");
textField.setValueAttribute("bob@smith.com");
HtmlPasswordInput textField2 = form.getInputByName("pass");
textField2.setValueAttribute("ladeeda");
HtmlPage page2 = button.click();

ただし、正しいメールアドレスとパスワードで facebook にログインしようとすると、次の 2 つの問題が発生します。

SEVERE: Job run failed with unexpected RuntimeException: TypeError: Cannot find 
function addImport in object [object]. 
(http://static.ak.fbcdn.net/rsrc.php/yC/r/gmR3y_ARtaM.js#10)

Exception class=[com.gargoylesoftware.htmlunit.ScriptException]
com.gargoylesoftware.htmlunit.ScriptException: TypeError: Cannot read property "length"         
from undefined (http://static.ak.fbcdn.net/rsrc.php/yC/r/gmR3y_ARtaM.js#10)

私は何を間違っていますか?

4

1 に答える 1

1

htmlunit が一部の JavaScript を気に入らないようです。

ログインには必要ないはずなので、オフにしてみてください。

webClient.setJavaScriptEnabled(false);
于 2011-01-21T13:08:47.347 に答える