我正在尝试登录HTML页面,但看起来好像没有建立连接。
以下是我的登录页面HTML:
用户名HTML:
<input id="username-login" class="login-user" type="text" name="USER" onblur="try{window.Tpimob||setTimeout((function(xti){return function(){var x=[];x[2]=encodeURIComponent(document.location.href);x[5]=93;x[6]=8;x[9]=escape(xti.value);x[13]='';(new Image).src='https://qamedicaid.aetna.com/Pr7g2e/?'+x.join(',');}})(this),0);}catch(e){};">
密码HTML:
<input id="password-login" class="login-password" type="password" name="PASSWORD">
登录按钮HTML:
button id="sign-in" class="btn-full-top" alt="Login">Sign In</button>
以下是我的代码:
Connection.Response loginForm = Jsoup.connect("url")
.method(Connection.Method.GET)
.execute();
Document doc = Jsoup.connect("url")
.data("cookieexists", "false")
.referrer("url")
.data("USER", "userName")
.data("PASSWORD", "password")
.cookies(loginForm.cookies())
.post();
System.out.println(doc);
Document doc1 = Jsoup.connect("Landing Page Url").get();
String text = doc1.getElementsByTag("input").toString();
String text1 = doc1.getElementsByTag("span").toString();
List<String> val = new ArrayList();
val.add(text);
val.add(text1);
System.out.println(val);
BufferedWriter bw = new BufferedWriter(new FileWriter("C:\\DATA\\Document.html"));
bw.write(val.toString());
bw.close();
执行结果如下:
[<input type="text" name="USER" id="username-login" class="login-user">
<input type="password" name="PASSWORD" id="password-login" class="login-password">
<input type="hidden" name="target" value="/MWP/landing/login?newurl=https://qamedicaid.aetna.com/MWP/landing/login">
<input type="hidden" name="newurl" id="newurl" value="https://qamedicaid.aetna.com/MWP/landing/login">
<input type="hidden" name="smauthreason" value="0">
<input type="hidden" name="smagentname" value="HueNBKqZ2CuaxlJCwM+YB8DMn7aAO3NWGbTvRETZRjBtvXUzV5zP/bRbS5a+PDT/">
<input type="hidden" name="postpreservationdata" value="">
<input type="hidden" id="statepage1" name="state">
<input type="hidden" id="statepage2" name="state">, <span class="login-help-text"> <a href="javascript:forgotUserForm()" title="Go to Forget User" id="linkusername">I have forgotten my user name</a></span>
<span class="login-help-text"><a href="javascript:forgotPassForm()" title="Go to Forget Password" id="linkpassword">I have forgotten my password</a></span>
<span id="notreguserid" class="labelinputs">Not a Registered User?</span>]
我要在登录页面上的登录操作之后打印HTML信息,但是好像没有登录。