HtmlUnit 使用范例

本文介绍了如何使用HtmlUnit库进行网页模拟操作,包括设置JavaScript支持、处理SSL证书问题和进行网页元素交互。示例代码展示了登录过程,并列举了项目所依赖的各个库。
摘要由CSDN通过智能技术生成

可以结合 Jsonp 解析

官方网站:http://htmlunit.sourceforge.net/dependencies.html

下载地址:https://sourceforge.net/projects/htmlunit/files/htmlunit/

 

/**
 * If set to <code>true</code>, the client will accept connections to any host, regardless of
 * whether they have valid certificates or not. This is especially useful when you are trying to
 * connect to a server with expired or corrupt certificates.
 * @param useInsecureSSL whether or not to use insecure SSL
 */
public void setUseInsecureSSL(final boolean useInsecureSSL) {
    useInsecureSSL_ = useInsecureSSL;
}

 

所以在init()时,也就是构造一个webclient时 ,打开最后的注释行即可解决这个异常……

public void init() throws Exception {
        webclient = new WebClient(BrowserVersion.FIREFOX_17);
        webclient.getOptions().setJavaScriptEnabled(true);
        webclient.getOptions().setThrowExceptionOnScriptError(false);
        webclient.getOptions().setCssEnabled(false);
        webclient.getCookieManager().clearCookies();
        webclient.getCache().clear();
        webclient.setRefreshHandler(new ImmediateRefreshHandler());
        webclient.getOptions().setTimeout(600*1000);
        webclient.setJavaScriptTimeout(600*1000);   
        webclient.setAjaxController(new NicelyResynchronizingAjaxController());  
        webclient.getOptions().setJavaScriptEnabled(true);   
        webclient.setJavaScriptTimeout(600*1000);   
        webclient.getOptions().setRedirectEnabled(true);
        webclient.waitForBackgroundJavaScript(60*1000);
        webclient.getOptions().setThrowExceptionOnScriptError(false);   
        webclient.getOptions().setThrowExceptionOnFailingStatusCode(false);
//        w

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值