java读取银联账单
在本文中,我将展示如何使用HtmlUnit从网站下载账单(或其他文件)。
我建议您先阅读这些文章: Java和Autologin的 Web抓取简介
由于我在Digital Ocean上托管了此博客(如果您通过此链接注册,可节省10美元的信用),因此我将展示如何编写一个自动下载每张账单的机器人。
登录
要提交登录表单而不需要检查dom,我们将使用我在上一篇文章中编写的魔术方法。
然后,我们必须转到帐单页面: https://cloud.digitalocean.com/settings/billing
: https://cloud.digitalocean.com/settings/billing
String baseUrl = "https://cloud.digitalocean.com" ;
String login = "email" ;
String password = "password" ;
try {
WebClient client = Authenticator . autoLogin ( baseUrl + "/login" , login , password );
HtmlPage page = client . getPage ( "https://cloud.digitalocean.com/settings/billing" );
if ( page . asText (). contains ( "You need to sign in for access to this page" )){
throw new Exception ( String . format ( "Error during login on %s , check your credentials" , baseUrl ));
}
} catch ( Exception e ) {
e