Well, I had some free time at work, and I thought to help and write it for you. Excuse me for any mistakes the first time I took apart the site, I did a little research and decided to use jSoup for this.
Well, this code will analyze a table and a system of three columns with values, you can change the code and build it according to your needs :)
You need to download jsoup jar Download jSoup
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.URL;
import java.net.URLConnection;
import java.util.Iterator;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
public class ParseWithJsoup{
public static void main(String[] args) {
URL url;
try {
url = new URL("http://www.cbsa-asfc.gc.ca/bwt-taf/menu-eng.html");
URLConnection conn = url.openConnection();
BufferedReader buffRead = new BufferedReader(new InputStreamReader(conn.getInputStream()));
StringBuffer buffer = new StringBuffer("");
String inputLine = "";
while (inputLine != null){
inputLine = buffRead.readLine();
buffer.append(inputLine);
}
Document doc = Jsoup.parse(buffer.toString());
Element table = doc.select("table[class=bwt]").first();
Iterator<Element> officeElements = table.select("td[headers=Office]").iterator();
Iterator<Element> comElements = table.select("td[headers=Com ComCanada]").iterator();
Iterator<Element> travElements = table.select("td[headers=Trav TravCanada]").iterator();
while(officeElements.hasNext()){
System.out.println("Office: " + officeElements.next().text());
System.out.println("Commercial Flow: " + comElements.next().text());
System.out.println("Travellers Flow: " + travElements.next().text());
}
}
catch (Exception e){
System.out.println("Exc:"+e.getMessage());
}
}
}
`
source
share