3 Replies Latest reply: Oct 22, 2012 1:48 PM by DrClap RSS

    executing a hyperlink

    824461
      Hi

      I have created a url connection which return the html of a website. Now there is a submit button in that html, How I can submit that button and get the response which JAVA
      URL url = new URL("<some url>");
                URLConnection urlConn = url.openConnection();
                
                BufferedReader br = new BufferedReader(new InputStreamReader(urlConn.getInputStream()));
      The website does not have captcha. Also Do I need to use servlets for this requirement or from J2SE apis only I can do it.

      Thanks
      Abhishek
        • 1. Re: executing a hyperlink
          Kayaman
          821458 wrote:
          I have created a url connection which return the html of a website. Now there is a submit button in that html, How I can submit that button and get the response which JAVA
          You need to perform a POST request on the address of the form where the submit button is.
          Also Do I need to use servlets for this requirement or from J2SE apis only I can do it.
          No you don't need servlets. You can Google for "Java POST url" or similar to find examples.
          • 2. Re: executing a hyperlink
            824461
            Kayaman wrote:
            821458 wrote:
            I have created a url connection which return the html of a website. Now there is a submit button in that html, How I can submit that button and get the response which JAVA
            You need to perform a POST request on the address of the form where the submit button
            I have requirement where after clicking submit button I have something else to send to the server. I am looking for doing things just like we do in browser.

            1. Logging in a web site programatically. As suggested I can send Post request and get a HTML as an output.
            2. Now I got the html, I want to submit a button on that html.
            3. on the generated output I still want to submit one more form.

            Through Post url I can post a request to a form but how can I do subsequent interaction with the server.
            • 3. Re: executing a hyperlink
              DrClap
              More interaction with the server? That would just require more POST (or maybe GET) requests being sent. That's what the browser does whenever you click on a link or a button, so that's what you should do too.

              You might want to consider using something like HTMLUnit which takes care of all the bookkeeping that you have to do in this web-scraping sort of scenario.