0

I am looking to get data from http://www.sportinglife.com/greyhounds/abc-guide and insert it into a table within Java. As you can see from the webpage, there is already a table with two columns, dog name and race. That is what I would like to replicate within my Java program, and then use JavaFX to output the table to a table view.

What would you recommend as the best way to do this using Java?

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
re0603
  • 387
  • 1
  • 4
  • 19

1 Answers1

1

You need to read the HTML from the web page and then parse the HTML DOM to get the table data

String url = "http://www.sportinglife.com/greyhounds/abc-guide";
URL obj = new URL(url);
HttpURLConnection con = (HttpURLConnection) obj.openConnection();

// optional default is GET
con.setRequestMethod("GET");

//add request header
con.setRequestProperty("User-Agent", USER_AGENT);

int responseCode = con.getResponseCode();
System.out.println("\nSending 'GET' request to URL : " + url);
System.out.println("Response Code : " + responseCode);

BufferedReader in = new BufferedReader(
new InputStreamReader(con.getInputStream()));
String inputLine;
StringBuffer response = new StringBuffer();

while ((inputLine = in.readLine()) != null) {
    response.append(inputLine);
}
in.close();
//print result
System.out.println(response.toString());

For parsing you can refer Java HTML Parsing

Community
  • 1
  • 1
Suneesh
  • 469
  • 7
  • 21