The question is can I use Jsoup to post login data that is controlled by javascript? Here's the info so far
Login URL for the site:
http://www.cybernations.net/login.asp
(they do have a no-bots policy, but I emailed the admin and have permission to auto-login for downloading game datafiles)
URL where files are stored
http://www.cybernations.net/stats_downloads.asp
The line of code where I use Jsoup to parse the html of the login page to show me the scripts...
Elements scriptTags = doc.getElementsByTag("script");
The output of looping through the list of Elements...
<!--
function FrontPage_Form1_Validator(theForm)
{
if (theForm.Username.value == "")
{
alert("Please enter a value for the \"Username\" field.");
theForm.Username.focus();
return (false);
}
if (theForm.Username.value.length > 40)
{
alert("Please enter at most 40 characters in the \"Username\" field.");
theForm.Username.focus();
return (false);
}
if (theForm.Validate_Password.value == "")
{
alert("Please enter a value for the \"Password\" field.");
theForm.Validate_Password.focus();
return (false);
}
if (theForm.Validate_Password.value.length < 1)
{
alert("Please enter at least 1 characters in the \"Password\" field.");
theForm.Validate_Password.focus();
return (false);
}
if (theForm.Validate_Password.value.length > 50)
{
alert("Please enter at most 50 characters in the \"Password\" field.");
theForm.Validate_Password.focus();
return (false);
}
return (true);
}
//-->
EDIT 1: edited the connection code Current code for login looks like so, returning the login page.
Connection.Response loginForm = Jsoup.connect( loginURL )
.method(Connection.Method.GET)
.execute();
Document document = Jsoup.connect( loginURL )
.data("Login", "Login")
.data("Username", user )
.data("Validate_Password", pass )
.cookies(loginForm.cookies() )
.post();
I feel like I'm missing something really simple here, should I direct the connect() method to follow redirects?
EDIT 2: Thanks for all your help, I think I'm going to switch to Apache's http client as it will (hopefully) give me greater control over the connection. Thank you all!