【问题标题】:apache HTMLUNIT..... PROBLEM in handling javascriptapache HTMLUNIT .....处理javascript的问题
【发布时间】: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


    【解决方案1】:

    According to their site JavaScript 支持由Mozilla Rhino 提供,因此您可能只需将其添加到您的类路径中(可能还需要调整一些配置)。

    另外,HtmlUnit 有professional support

    【讨论】:

    • 我已经将我的问题发布到 HtmlUnit 邮件列表 (htmlunit-user@lists.sourceforge.net) 和 HtmlUnit 专业支持 (efficient-webtesting.com) 我已经安装了 Mozzilla Rhino 并将其添加到我的类路径。你能告诉我我需要修改什么配置吗?
    • 请将 com.gargoylesoftware.htmlunit.javascript looger 设置为调试级别,以便查看正在执行的内容。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-01-11
    • 2011-11-22
    • 2011-11-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-12-07
    相关资源
    最近更新 更多