• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Java newbie question

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I wanted to do this task,of logging into a website with a username and a password.Once i am there on the page i want to simulate a click on a link(dont know if simulate is the right word.. ).The click would give me a page where there is data arranged in a table.This data has to be stored in a text file.

Once this is done a simple logout would finish my task.

I am not sure how and using what technologies should i accomplish this task.Can someone help me with the approach that i should take to do this task.

Thanks.
 
Ranch Hand
Posts: 276
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Basically what you need to do is send GET/POST requests to the page, provided that it's a simple HTML page, no fancy Javascript/Flash buttons, etc. I'd recommend using the Jakarta Commons HttpClient!
 
Marshal
Posts: 79180
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Welcome to JavaRanch

Please always tell us what the thread is about. "Java newbie question" doesn't give us much inspiration to answer . Also, I think the "newbie" bit is inaccurate; this is a question beyond the "beginning" stage, and GET/POST looks like something out of a servlet, so I shall move this post thither. If I was mistaken about the location, it may move again, but you can still find the thread from "beginning"
 
tyler durt
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


I am up with the HTTPClient module,but was stuck with a few things.

1.My code is supposed to login to a site and get the data,but here what i see is a html source which is nothing but a login page.

2.How can i click on a particular link on a page.


Here's the code that i was trying to use:


import org.apache.commons.httpclient.*;
import org.apache.commons.httpclient.auth.HttpAuthRealm;
import org.apache.commons.httpclient.methods.*;


public class SecureGetPageExample {
public static void main( String[] args ) {
/*if( args.length < 3 ) {
System.out.println( "Usage: java GetPageExample URL username password" );
System.exit( 0 );
}*/
String url = "http://www.gmail.com";
String username = "";
String password = "";
try {
HttpClient client = new HttpClient();
client.getState().setCredentials(
new HttpAuthRealm(password, username),
new UsernamePasswordCredentials( username, password ) );
GetMethod method = new GetMethod( url );
method.setFollowRedirects( true );

// Execute the GET method
int statusCode = client.executeMethod( method );
if( statusCode != -1 ) {
String contents = method.getResponseBodyAsString();
method.releaseConnection();
System.out.println( contents );

}
}
catch( Exception e ) {
e.printStackTrace();
}
}
}
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic