A preserved archive of the Logical Gamers community forums, 2009-2025. The original threads and posts, served read-only. Registration, posting and private messages are gone for good.

The JSoup website is down, so does anyone feel like helping me?

1.1k views · started by 323 ·
#1
The JSoup website is down, so does anyone feel like helping me?
Trying to do the Gaia Login in Java. I was thinking of using JSoup to fetch all of the names of the inputs, and then fetch the values so that I could then submit them with the username and password to login. I can't figure out how to fetch the name of a randomly-named field though, but it seems like there's some next() thing I could use. I can't be sure though, because I can't check on the JSoup website because it's down.

I already have the username and password submit set up:


import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;

public class Login
{
public static void main(String[] args) throws UnsupportedEncodingException
{
String lookfor = "from your Gaia account";
String postData = "username=" + URLEncoder.encode("userhere", "UTF-8") +
"&password=" + URLEncoder.encode("passhere", "UTF-8");
HTTPRequest request = new HTTPRequest();
request.setURL("http://www.gaiaonline.com.com");
System.out.println("Request: " + request);
System.out.println("URL: " + request.getURL());
System.out.println("Get: " + request.get());
System.out.println("Post: " + request.post("/auth/login", postData));
System.out.println("Get: " + request.get());
int index1 = request.get().indexOf(lookfor);
if (index1 != -1)
{
System.out.println("Login Success");
}
else
{
System.out.println("Login Failed");
}
}
}


But I need to use JSoup to grab the SID and Token and randomly generated input and then submit those too.

I had this as code to try to grab SID a few months ago, but I forget how it worked and it's not producing any output lol:


import org.jsoup.Jsoup;
import org.jsoup.helper.Validate;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;

import java.io.IOException;

class JSoupTest {
public static void main(String[] args) throws IOException {
Document doc = Jsoup.connect("http://gaiaonline.com/auth/login").get();
Elements inputs = doc.select("sid");
for(Element input : inputs) {
System.out.println(input.attr("name"));
System.out.println(input.attr("value"));
}
}
}


And I can't check my code and see what it does or anything, because the JSoup website is down.

Anyway, thanks.
#3
Stapled wrote:
How do I get a substring between tags in a String? - Web Tutorials - avajava.com

There is an example on that page what would allow you get all substrings between two strings. You could do something like that to get the names and values.


That's actually like exactly what I need, thanks a ton for that. I'll try to post my Gaia login once I have it finished up.

EDIT: Having a few problems.

This is my source:

import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import org.apache.commons.lang.StringUtils;

public class GaiaLogin
{
public static void main(String[] args) throws UnsupportedEncodingException
{
String lookfor = "The username or password";
HTTPRequest request = new HTTPRequest();
request.setURL("http://www.gaiaonline.com/auth/login");
System.out.println("URL: " + request.getURL());
String source = request.get();
if (source != null) {
System.out.println("Source successfully grabbed: " + source);
}
else {
System.out.println("Error: Couldn't grab page source!");
}
String title = StringUtils.substringBetween(source, "<title>", "</title>");
System.out.println("Title: " + title); //Print out page title, for testing purposes
String sid = StringUtils.substringBetween(source, "name=\"sid\" value=\"", "\" type=\"hidden\" />");
System.out.println("SID: " + sid); //Print out Session ID
String token = StringUtils.substringBetween(source, "name=\"token\" value=\"", "\" />");
System.out.println("Token: " + token); //Print out token value
String rname = StringUtils.substringBetween(source, "<input type=\"hidden\" name=\"", "\" value=\"");
System.out.println("Random Input Name: " + rname); //Prints out random input name
String rvalue = StringUtils.substringBetween(source, "name=\"" + rname + "\" value=\"", "\" />");
System.out.println("Random Input Value: " + rvalue); //prints out random input value
}
}


and I'm getting this as output:

URL: http://www.gaiaonline.com/auth/login
Source successfully grabbed: *the source was here*
Title: Log In | Gaia Online
SID: null
Token: null
Random Input Name: null
Random Input Value: null


Any idea why I'm getting null for everything? This is extremely confusing to me, I can't think of any reason why I would be getting this output.
#4
My first time touching java in ~3 years.

import java.io.UnsupportedEncodingException;
import org.apache.commons.lang.StringUtils;

public class GaiaLogin
{
public static void main(String[] args) throws UnsupportedEncodingException
{
String lookfor = "The username or password";
HTTPRequest request = new HTTPRequest();
request.setURL("http://www.gaiaonline.com/");
System.out.println("URL: " + request.getURL());
String source = request.get();
if (source != null) {
System.out.println("Source successfully grabbed: " + source);
}
else {
System.out.println("Error: Couldn't grab page source!");
}
String title = StringUtils.substringBetween(source, "<title>", "</title>");
System.out.println("Title: " + title); //Print out page title, for testing purposes

String posts = StringUtils.substringBetween(source, "</fieldset>", "</form>").replace("data-value", "");//limits the string search to the area with the data
//posts = posts.replace("data-value", "");
String[] names = StringUtils.substringsBetween(posts, "name=\"", "\"");//finds the names of the strings
String[] values = StringUtils.substringsBetween(posts, "value=\"", "\"");//finds the values of the strings
System.out.println(names[0] + " => " + values[0]);//prints the first name and value
System.out.println(names[1] + " => " + values[1]);//prints the second name and value
System.out.println(names[2] + " => " + values[2]);//prints the third name and value
System.out.println(names[3] + " => " + values[3]);//prints the fourth name and value

//login starts here
String user = "";
String pass = "";
String postdata = names[0] + "=" + values[0]
+ "&" + names[1] + "=" + values[1]
+ "&" + names[2] + "=" + values[2]
+ "&" + names[3] + "=" + values[3]
+ "&" + "&username=" + user + "&password=" + pass;
request.setURL("http://www.gaiaonline.com/auth/login/");
String login = request.post("", postdata);
if (login.contains("login_success")) {
System.out.println("Logged in successfully!");
}
else {
System.out.println("Login Failed!");
}
}
}[/3][/3][/2][/2][/1][/1][/0][/0][/3][/3][/2][/2][/1][/1][/0][/0]


Enjoy!
#5
Stapled wrote:
My first time touching java in ~3 years.

import java.io.UnsupportedEncodingException;
import org.apache.commons.lang.StringUtils;

public class GaiaLogin
{
public static void main(String[] args) throws UnsupportedEncodingException
{
String lookfor = "The username or password";
HTTPRequest request = new HTTPRequest();
request.setURL("http://www.gaiaonline.com/");
System.out.println("URL: " + request.getURL());
String source = request.get();
if (source != null) {
System.out.println("Source successfully grabbed: " + source);
}
else {
System.out.println("Error: Couldn't grab page source!");
}
String title = StringUtils.substringBetween(source, "<title>", "</title>");
System.out.println("Title: " + title); //Print out page title, for testing purposes

String posts = StringUtils.substringBetween(source, "</fieldset>", "</form>").replace("data-value", "");//limits the string search to the area with the data
//posts = posts.replace("data-value", "");
String[] names = StringUtils.substringsBetween(posts, "name=\"", "\"");//finds the names of the strings
String[] values = StringUtils.substringsBetween(posts, "value=\"", "\"");//finds the values of the strings
System.out.println(names[0] + " => " + values[0]);//prints the first name and value
System.out.println(names[1] + " => " + values[1]);//prints the second name and value
System.out.println(names[2] + " => " + values[2]);//prints the third name and value
System.out.println(names[3] + " => " + values[3]);//prints the fourth name and value

//login starts here
String user = "";
String pass = "";
String postdata = names[0] + "=" + values[0]
+ "&" + names[1] + "=" + values[1]
+ "&" + names[2] + "=" + values[2]
+ "&" + names[3] + "=" + values[3]
+ "&" + "&username=" + user + "&password=" + pass;
request.setURL("http://www.gaiaonline.com/auth/login/");
String login = request.post("", postdata);
if (login.contains("login_success")) {
System.out.println("Logged in successfully!");
}
else {
System.out.println("Login Failed!");
}
}
}[/3][/3][/2][/2][/1][/1][/0][/0][/3][/3][/2][/2][/1][/1][/0][/0]


Enjoy!


Impressive, I like it! I should've thought of using an array for the names and values, that's a great idea! Thanks a ton for helping me with this!