HTMLunit-Facebook登录 [英] HTMLunit - Facebook Login
本文介绍了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上的帐户.但是我遇到了这个错误:
I'm trying to use the HTMLUnit to log into an account on facebook. However I'm getting this error:
我正在寻找一个程序,该程序可以自动执行我在Facebook上的页面所执行的某些操作.我知道类似的东西可能已经存在,但我正在做它是为了好玩.
I'm looking to create a program that automates some of the things that I do with my pages that I have on facebook. I know something like this probably already exists but I'm making it for fun.
======= 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)
推荐答案
当我在WebClient构造函数中添加BrowserVersion时,我停止出现此错误:
I stopped getting this error when I added a BrowserVersion into the WebClient constructor:
final WebClient webClient = new WebClient(BrowserVersion.FIREFOX_38);
这篇关于HTMLunit-Facebook登录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文