package dk.thoerup.traininfoservice.banedk; /* Work in progress * */ import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.Date; import java.util.List; import java.util.logging.Logger; import com.gargoylesoftware.htmlunit.BrowserVersion; import com.gargoylesoftware.htmlunit.WebClient; import com.gargoylesoftware.htmlunit.html.DomNodeList; import com.gargoylesoftware.htmlunit.html.HtmlElement; import com.gargoylesoftware.htmlunit.html.HtmlPage; public class RejseplanenFetcher { Logger logger = Logger.getLogger(RejseplanenFetcher.class.getName()); SimpleDateFormat format = new SimpleDateFormat("HH:mm"); public String getNow() { return format.format( new Date() ); } public List lookupDepartures(int stationcode, String type, boolean arrival) throws Exception { List departureList = new ArrayList(); final WebClient webClient = new WebClient( BrowserVersion.FIREFOX_3 ); webClient.getCookieManager().setCookiesEnabled( false ); webClient.setTimeout(2500); webClient.setJavaScriptEnabled(false); String uri = "http://www.rejseplanen.dk/bin/stboard.exe/mn?ml=m&input=" + stationcode + "&boardType=dep&time=" + getNow() + "&productsFilter=11111000001&selectDate=today&maxJourneys=200&start=yes"; HtmlPage page = webClient.getPage(uri); HtmlElement table = page.getElementById("hafasSqResults"); if (table != null) { DomNodeList tableRows = table.getElementsByTagName("tr"); for (HtmlElement currentRow : tableRows) { String id = currentRow.getId(); logger.info("tr.id=" + id); String rowClass = currentRow.getAttribute("class"); if (rowClass != null && rowClass.indexOf("sqToggleDetails") != -1 ) { DomNodeList fields = currentRow.getElementsByTagName("td"); logger.severe("td count=" + fields.size()); if (fields.size() == 0) continue; for (int f=0; f