【发布时间】:2009-10-08 10:20:47
【问题描述】:
我想通过
登录一个网站 (http://www.orkut.com)com.gargoylesoftware.htmlunit.WebClient
但是当我点击“提交”按钮时,它并没有将我带到登录后应该出现的预期页面。相反,它再次返回相同的登录页面。显然,登录存在一些问题。当我在没有 javascript 的网站上尝试相同的代码时,它运行良好,所以我认为我无法处理脚本。
我正在尝试使用以下代码:
public static void main(String[] args) {
final WebClient webClient = new WebClient();
try {
HtmlPage loginPage = webClient.getPage(new URL("https://www.google.com/accounts/ServiceLogin?service=orkut&hl=en-US&rm=false&continue=http%3A%2F%2Fwww.orkut.com%2FRedirLogin%3Fmsg%3D0%26page%3Dhttp%253A%252F%252Fwww.orkut.co.in%252FHome.aspx&cd=IN&passive=true&skipvpage=true&sendvemail=false"));
System.out.println(loginPage.getTextContent());
List<HtmlForm> forms = loginPage.getForms();
HtmlForm loginForm = forms.get(0);
HtmlInput username = loginForm.getInputByName("Email");
HtmlInput password = loginForm.getInputByName("Passwd");
HtmlInput submit = loginForm.getInputByName("signIn");
username.setNodeValue("username");
password.setNodeValue("password");
HtmlPage homePage = submit.click();
Thread.sleep(10 * 1000);
System.out.println(homePage.getTextContent());
}catch(Exception ex) {
ex.printStackTrace();
}
}
当我们点击“提交”按钮时,实际上它首先调用了这个函数
onsubmit="return(gaia_onLoginSubmit());"
指定为下面表单的属性
<form id="gaia_loginform" action="https://www.google.com/accounts/ServiceLoginAuth?service=orkut" method="post"
onsubmit="return(gaia_onLoginSubmit());">
谁能帮帮我。
注意:我将为解决方案付费
【问题讨论】:
标签: java apache authentication webclient login-script