6

我正在使用在线银行应用程序。我想登录以取回余额。我一直在做一些研究,并从其他帖子中找到了一些有用的 HtmlUnit 代码。但是,我一直在处理页面的重定向。路径如下:主登录表单(page1),生成一个验证凭据的新页面(page2)。到目前为止我做得很好,但我找不到检索主页(page3)的解决方案,这里是代码:

import com.gargoylesoftware.htmlunit.BrowserVersion;
import com.gargoylesoftware.htmlunit.WebClient;
import com.gargoylesoftware.htmlunit.html.HtmlForm;
import com.gargoylesoftware.htmlunit.html.HtmlPage;

public class WellsF {
    public static void main(String[] args) throws Exception {

        WebClient webClient = new WebClient(BrowserVersion.CHROME_16);
        webClient.getOptions().setJavaScriptEnabled(true);
        webClient.getOptions().setThrowExceptionOnScriptError(false);
        webClient.getOptions().setCssEnabled(true);
        webClient.getOptions().setUseInsecureSSL(true);
        webClient.getOptions().setRedirectEnabled(true);

        HtmlPage page1 = webClient
                .getPage("https://www.wellsfargo.com/home.jhtml");

        final HtmlForm form = (HtmlForm) page1.getElementById("frmSignon");

        form.getInputByName("userid").setValueAttribute("user id");
        form.getInputByName("password").setValueAttribute("user password");

        HtmlPage page2 = (HtmlPage) form.getInputByName("btnSignon").click();

        synchronized (page2) {
            page2.wait(5000);
            System.out.println(page2.asText());
            System.out.println("=========================== page2\n");
        }

        HtmlPage page3 = (HtmlPage) webClient.openWindow(page2.getUrl(),
                "signon").getEnclosedPage();
        System.out.println(page3.asText());
        webClient.closeAllWindows();
    }
}
4

1 回答 1

0

你能试试下面的代码并检查它是否工作:

 HtmlPage page3 = (HtmlPage) webClient.getPage(page2.getUrl());
 webClient.getOptions().setTimeout(10*1000);
于 2015-10-06T07:30:04.203 回答