[英]Using HTMLUnit to log into Facebook programmatically using Java
This question is kinda an addition to this question: How to log into Facebook programmatically using Java? 这个问题有点像这个问题的补充: 如何使用Java以编程方式登录Facebook?
I have used (a slightly modified version of) the following code to log into accounts of other websites just fine. 我使用(略微修改版本)以下代码来登录其他网站的帐户就好了。
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();
However, whenever I attempt to log into facebook with correct email and password, I run into two problems: 但是,每当我尝试使用正确的电子邮件和密码登录Facebook时,我遇到两个问题:
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)
What am I doing wrong? 我究竟做错了什么?
It looks like htmlunit doesn't like some of the javascript. 看起来htmlunit不喜欢一些javascript。
Try switching it off as it shouldn't be necessary for login: 尝试将其关闭,因为登录时不需要:
webClient.setJavaScriptEnabled(false);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.