• Post Reply Bookmark Topic Watch Topic
  • New Topic

Clicking href button with java  RSS feed

 
Jeremy Park
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, I am trying to automate a website bot. I've hit a wall here, as there is a button on the website, that I need to click, but it returns a number using javascript that will access the page. Without that number, accessing the page won't work. Therefore, either I need to click the button, or return that data when I access the url. Here is the line in the html.

<a href="/missions.php?jid=11&cat=2&formNonce=49af09362db790a6b364401c4ea52a08b515df4a&h=284e4fe4946e6fb8af3a662f4583454eebc8bd23" class="actionButton" onclick="return fsb11('5494');">Do It</a>

As you see, it returns in this case fsb11('5494'). I need to replicate this in an automatic way. Please help if you can. Thanks
 
Ulf Dittmer
Rancher
Posts: 42972
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch.

How are you accessing the site? If this was my problem I'd use the HtmlUnit library - which supports JavaScript.
 
Jeremy Park
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ulf Dittmer wrote:Welcome to the Ranch.

How are you accessing the site? If this was my problem I'd use the HtmlUnit library - which supports JavaScript.


I'm trying to access the site using HttpUrlConnection, and/or JavaFX WebEngine.

I've looked into HtmlUnit, as it looks like it would do the job, but I would like to find a way to import it directly into my Java project, as I would like to make it possible to run this program without dependencies. Is there a way to at least do that? Thanks.
 
Ulf Dittmer
Rancher
Posts: 42972
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What do you mean by "import it directly"? The code would depend on all the HtmlUnit jars and its dependencies (there are several). What is the purpose of trying to make do without dependencies?
 
Jeremy Park
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ulf Dittmer wrote:What do you mean by "import it directly"? The code would depend on all the HtmlUnit jars and its dependencies (there are several). What is the purpose of trying to make do without dependencies?


If I were to import HtmlUnit as a library, as far as I am aware, I wouldn't be able to then export my project as a .jar, and then run it from a computer that doesn't have HtmlUnit in the location I imported it from. Am I incorrect here?
 
Ulf Dittmer
Rancher
Posts: 42972
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"Export to a jar" sounds like IDE-specific functionality, so I guess that depends on what the IDE in question does. The usual approach is to list all jar files as classpath dependencies in the manifest files of your jar file, and ship them together with your code. The first two sections of http://docs.oracle.com/javase/tutorial/deployment/jar/index.html describe all that in detail.
 
Jeremy Park
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ulf Dittmer wrote:"Export to a jar" sounds like IDE-specific functionality, so I guess that depends on what the IDE in question does. The usual approach is to list all jar files as classpath dependencies in the manifest files of your jar file, and ship them together with your code. The first two sections of http://docs.oracle.com/javase/tutorial/deployment/jar/index.html describe all that in detail.


I am using Eclipse Luna at the moment. What I would ideally like to do is to import the .java files for HtmlUnit directly into my Java Project, so that when I create my Java project into a runnable .jar file, all of the HtmlUnit source code will be inside of that .jar.

I managed to do this with JSoup, but for some reason when I try with HtmlUnit, it just imports as a folder, and not a package. I really don't want to have to have it external to the .jar. Is there any way around that?
 
Ulf Dittmer
Rancher
Posts: 42972
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
(I assume that "HtmlUnit source code" is a typo, and you meant "HtmlUnit class files" - including the source code generally makes little sense.)

Yes, it is possible to package the classes contained in numerous jar files all into one jar file. Tools like http://one-jar.sourceforge.net/ can do this. I'll move this topic to the IDE forum, maybe someone there knows how to do that from within Eclipse.
 
Jeremy Park
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ulf Dittmer wrote:(I assume that "HtmlUnit source code" is a typo, and you meant "HtmlUnit class files" - including the source code generally makes little sense.)

Yes, it is possible to package the classes contained in numerous jar files all into one jar file. Tools like http://one-jar.sourceforge.net/ can do this. I'll move this topic to the IDE forum, maybe someone there knows how to do that from within Eclipse.


What I meant by the source code was the .java files. That way I could import them as part of my java program. I haven't actually tried importing class files that way yet. Anyway, I successfully managed to import them, and then I found out how many dependencies that HtmlUnit has. I am currently looking for a more streamlined alternative.
Thanks for your help.
 
Paul Clapham
Sheriff
Posts: 22839
43
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jeremy Park wrote:What I meant by the source code was the .java files. That way I could import them as part of my java program. I haven't actually tried importing class files that way yet.


You don't need the source code of something which you want to import into your Java code. The "import" command only uses compiled classes, and it gets them from the classpath.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!