wood burning stoves 2.0*
The moose likes Beginning Java and the fly likes Accessing Html web page components from normal Java Application. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Accessing Html web page components from normal Java Application." Watch "Accessing Html web page components from normal Java Application." New topic
Author

Accessing Html web page components from normal Java Application.

Yves Kraasch
Greenhorn

Joined: Jun 02, 2011
Posts: 4

Howdy,

right now I'm working on an Java Application that can do the weekly »signing in« to some sport activities for me.
Thus, I have to access the Web Page of my sports club, where I leave my 'user name' and 'password'.
The programm doing all the work for me should be as far as possible abstracted from this use.
In such a way that if my sports club alters the actual web page design, I don't have to do the whole work all over again.

My question is:
How can I gain access to certain Html components, i. e. the password text field?

I'm assuming that I know the name of the correlating Html component:
I already have an algorithm that lists me the component names on a Html web page.

Another question would be:
Having access to an Html component, how can I submit the data I just wrote into the Html form?

So long!
And thanks for the trouble
Tim Moores
Rancher

Joined: Sep 21, 2011
Posts: 2408
There's a library that can handle all that for you; it's called HtmlUnit.
Yves Kraasch
Greenhorn

Joined: Jun 02, 2011
Posts: 4

Thanks for your answer so far!

Are there any other possibilities?

What I mean is:
To display a website all I need are about 5 lines of code.
(Chaining two Streams, outputting the content in a TextArea)

Writing to a website seems to be rather complicated.
Tim Moores
Rancher

Joined: Sep 21, 2011
Posts: 2408
We can't really suggest alternative unless you tell us how the one suggested already doesn't meet your needs.

What do you mean by "display a web site"? So far you talked about reading data from a site and submitting an HTML form.

What do you mean by "writing to a web site"? Submitting an HTML form is covered on the page I linked to.
Yves Kraasch
Greenhorn

Joined: Jun 02, 2011
Posts: 4

Ok.

This is what I ment by display a web site:

This reads the data from the site, but doesn't allow me to submit Html forms back to the server.

By writing to a web site I mean addressing it in a way I can do it manually using a web browser.
For me it's not important to immitate high-level interaction with the server, if this means submitting an Html form.
If there are other ways to address the server, maybe by using PHP, that suits me as well.
If there is no difference between addressing a server using PHP and submitting an Html form, I'll probably use HtmlUnit.

To be more precise:
At the end I'd like my application to immitate that someone has entered a keyword into the wikipedia search form.
As if this someone was using a web browser.

Here is an extract of the Html search form from en.wikipeda.org:


I tried addressing it with HtmlUnit but it didn't do as I wanted it to.
Having read in the HtmlForm ("searchform") from the web page I tried reading in the "button" and the "search" from the searchform.
But it seems as the HtmlForm doesn't know about those HtmlElemnts.
At least, if I try getInputByName, as shown on the Gargoyle Software site.
I tried other methods: Those find the elements but I can't use those for submission.

Can you help me with this problem?
If not, maybe you know about how one can work one's way into HtmlUnit.
How do you manage new APIs ?

By the way, this is some of my testing:

Thank you very much for your work so far!
Tim Moores
Rancher

Joined: Sep 21, 2011
Posts: 2408
OK, so you have tried some code; that's good. What, exactly, does that code do, and how does that differ from what you would like to accomplish?
Yves Kraasch
Greenhorn

Joined: Jun 02, 2011
Posts: 4

What exacty do you need more information about to help me?
Tim Moores
Rancher

Joined: Sep 21, 2011
Posts: 2408
You misunderstand. I'm not trying to help you by writing the code for you, I'm trying to help you by nudging you in the right direction. Explicitly stating the problem is often a good way to seeing the actual problem (and then being able to address it).
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Accessing Html web page components from normal Java Application.