Integration software website Java [closed]

1

My question is this: I and my team are developing software that analyzes a table with specific data, but to generate this table we use a website where you enter an information and this website analyzes and generates all the data about this information in a table in html. Most of us have basic and intermediate knowledge of java, so I would like to know if there is a way to make a program that will receive the input, consult that website, enter the past information, collect the result in html and return only this result already soon.

Edit: Here is the part of my code that makes the connection, the site receives a genetic sequence, processes and then returns a table in html. What I want is for my system to connect, send the sequence and capture the response.

package wangConn;

import java.io.BufferedReader;
import java.io.DataOutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLEncoder;

public class WangConnection {
public static void main(String[] args) {
    String param1 = "ATGCCCCCGACGCCCCCGGGGGGTGA", param2="Submit";
    URL url;
    HttpURLConnection connection = null;
    BufferedReader in = null;
    DataOutputStream out = null;
    try {
        // Mounting content to be sent
        String data = "seqfield=" + URLEncoder.encode(param1, "UTF-8");
        data += "Submit=" + URLEncoder.encode(param2, "UTF-8");

        url = new URL("http://wangcomputing.com/assp/");
        // Make connection with the specified URL
        connection = (HttpURLConnection)url.openConnection();
        // Enable writing on URLConnection
        connection.setDoOutput(true);
        // Connect using the POST method
        connection.setRequestMethod("POST");
        // Define the requisition type
        connection.setRequestProperty("Content-Type",
                "application/x-www-form-urlencoded");

        // Send data
        out = new DataOutputStream(
                connection.getOutputStream());
        out.writeBytes(data);
        out.flush();
        out.close();

        // Getting return from the connection
        String line;
        in = new BufferedReader(new InputStreamReader(connection.getInputStream()));
        while((line = in.readLine()) != null) {
            System.out.println(line);
        }
    } 
    catch (MalformedURLException ex) {
        System.out.println("Bad format URL: " + ex.getMessage());
    }
    catch (IOException ex) {
        System.out.println("Unable to connect: " + ex.getMessage());
    }
    finally {
        if(out != null) {
            try {
                out.close();
            } 
            catch (IOException ex) {
                System.out.println("Unable to close input stream: " + ex.getMessage());
            }
        }
        if(in != null) {
            try {
                in.close();
            } 
            catch (IOException ex) {
                System.out.println("Unable to close output stream: " + ex.getMessage());
            }
        }
        connection.disconnect();
    }
  }
}

My problem now is that the website I'm trying to submit form on the website to no avail. The type of input used:     

    
asked by anonymous 26.05.2015 / 19:39

1 answer

1

You need to enter the URL and capture the information inside the element you want. Here's how to access a URL in java:

public static void main(String[] args) {
    URL url;
    InputStream is = null;
    BufferedReader br;
    String line;

    try {
        url = new URL("http://stackoverflow.com/");
        is = url.openStream();  // throws an IOException
        br = new BufferedReader(new InputStreamReader(is));

        while ((line = br.readLine()) != null) {
            System.out.println(line);
        }
    } catch (MalformedURLException mue) {
         mue.printStackTrace();
    } catch (IOException ioe) {
         ioe.printStackTrace();
    } finally {
        try {
            if (is != null) is.close();
        } catch (IOException ioe) {
            // nothing to see here
        }
    }
}

When you have HTML, you may want to filter it. Look at this link showing an alternative. JSOUP

String html = "<p>An <a href='http://example.com/'><b>example</b></a> link.</p>";
Document doc = Jsoup.parse(html);
Element link = doc.select("a").first();

String text = doc.body().text(); // "An example link"
String linkHref = link.attr("href"); // "http://example.com/"
String linkText = link.text(); // "example""

String linkOuterH = link.outerHtml(); 
    // "<a href="http://example.com"><b>example</b></a>"
String linkInnerH = link.html(); // "<b>example</b>"
    
26.05.2015 / 23:18