I'm trying to login to this website with my credentials with JSoup.
Source code:
<form id="frm_login" autocomplete="off">
<ol>
<li>
<span id="lblcgspan" style="display:inline;">
<label for="parama">CougarNet ID:</label>
</span>
<span id="lblpsspan" style="display:none;">
<label for="parama">myUH (PeopleSoft) ID:</label>
</span>
<input type="text" id="parama" name="parama" class="required" tabindex="1" />
<span id="lnkcghelpspan" style="display:inline;">
<a target="_blank" href="http://ift.tt/1wFoKBm">Don't know your CougarNet ID?</a>
</span>
<span id="lnkpshelpspan" style="display:none;">
<a target="_blank" href="http://ift.tt/1zBMgd5;">Don't know your myUH (PeopleSoft) ID?</a>
</span>
</li>
<li>
<span id="lblcgpwdspan" style="display:inline;">
<label for="paramb">CougarNet Password:</label>
</span>
<span id="lblpspwdspan" style="display:none;">
<label for="paramb">myUH (PeopleSoft) Password:</label>
</span>
<input type="password" id="paramb" name="paramb" class="required" tabindex="2"/>
<span id="lnkcgpwdspan" style="display:inline;">
<a target="_blank" href="http://ift.tt/1y7ANo1">Change your CougarNet Password.</a>
</span>
<span id="lnkpspwdspan" style="display:none;">
<a target="_blank" href="http://ift.tt/1zBMgd9">Change your myUH (PeopleSoft) Password.</a>
</span>
</li>
<li>
<div style="width: 150px; float: left;"> </div>
<input type="hidden" value="1" name="popup" />
<input class="submit pslogin-button" type="submit" id="login-button" value="Login to AccessUH" tabindex="3"/>
</li>
<span id="lstsvcspan" style="display:none;">
<li>Not all services are available in AccessUH when using the myUH (PeopleSoft) credentials.
</li>
</span>
</ol>
<p class="center"><label id="error_msg" class="error"></label></p>
<input type="hidden" name="paramd" value="9cb83e96b0e5f6354f07d1db0e7f6cb9"/>
<input type="hidden" name="paramg" id="paramg" value="cglg" />
<input type="hidden" name="paramm" id="paramm" value="" />
</form>
</div>
Here's what I'm trying to do:
import java.io.IOException;
import java.util.Map;
import org.jsoup.Connection;
import org.jsoup.Connection.Method;
import org.jsoup.Connection.Response;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;
import javax.swing.plaf.synth.SynthScrollBarUI;
public class trial {
public static void main(String[] args) {
Response res = Jsoup
.connect("http://ift.tt/1zBMelt")
.data("parama", "userName", "paramb", "Password")
.method(Method.POST)
.execute();
//cookies
Map<String, String> loginCookies = res.cookies();
Document loggedIn = Jsoup.connect("http://ift.tt/1wFoKBo") // I should be able to access this URL after logging in
.cookies(loginCookies)
.get();
// this should be able to print out the links on the page I'm able to access after logging in
Elements links = loggedIn.select("a[href]");
System.out.println(links.html() );
}
}
For someone reason I'm unable to log in and parse the logged in page. Could you please point to me what I'm doing wrong?
Aucun commentaire:
Enregistrer un commentaire