apache HTMLUNIT.....处理 javascript 时出现问题

发布于 2024-08-06 13:47:17 字数 1759 浏览 2 评论 0原文

我想通过以下方式登录网站 (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());">

函数任何人都可以帮助我。

注意:我将支付解决方案费用

I want to login to a website (http://www.orkut.com) through

com.gargoylesoftware.htmlunit.WebClient

But when I click on the "Submit" button, it doesn't take me to the expected page that should come after login. Instead it returns the same login page again. In clear sense, there is some problem in login. When I try the same code with sites that doen't have javascript, it works fine so I think I am not able to handle scripts.

I am trying using the follwoing code:

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();
    }
}

When we do click on the "submit" button, in actual it calls first this function

onsubmit="return(gaia_onLoginSubmit());"

specified as the attribute of the form below

<form id="gaia_loginform" action="https://www.google.com/accounts/ServiceLoginAuth?service=orkut" method="post"
    onsubmit="return(gaia_onLoginSubmit());">

Can anyone help me in this.

NOTE: I WILL PAY FOR THE SOLUTION

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

笨死的猪 2024-08-13 13:47:17

根据他们的网站,JavaScript 支持由 Mozilla Rhino,所以也许您需要的只是将其添加到您的类路径中(也许还需要修改一些配置)。

此外,HtmlUnit 还拥有专业支持

According to their site the JavaScript support is provided by Mozilla Rhino, so maybe all you need is to add it to your classpath (and perhaps fiddle with some configurations).

Also, HtmlUnit has professional support

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文