--- android/TrainInfoService/src/dk/thoerup/traininfoservice/banedk/RejseplanenFetcher.java 2010/07/10 10:53:44 978 +++ android/TrainInfoService/src/dk/thoerup/traininfoservice/banedk/RejseplanenFetcher.java 2010/07/14 09:49:56 993 @@ -4,17 +4,19 @@ * */ +import java.net.URL; 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; +import org.jsoup.Jsoup; +import org.jsoup.nodes.Document; +import org.jsoup.nodes.Element; +import org.jsoup.select.Elements; + + public class RejseplanenFetcher { @@ -30,49 +32,45 @@ 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); + Document doc = Jsoup.parse(new URL(uri), 2500); + - HtmlElement table = page.getElementById("hafasSqResults"); + Element table = doc.getElementById("hafasSqResults"); if (table != null) { - DomNodeList tableRows = table.getElementsByTagName("tr"); + Elements tableRows = table.getElementsByTag("tr"); - for (HtmlElement currentRow : tableRows) { - String id = currentRow.getId(); + for (Element currentRow : tableRows) { + String id = currentRow.id(); logger.info("tr.id=" + id); - String rowClass = currentRow.getAttribute("class"); + String rowClass = currentRow.attr("class"); if (rowClass != null && rowClass.indexOf("sqToggleDetails") != -1 ) { - DomNodeList fields = currentRow.getElementsByTagName("td"); + Elements fields = currentRow.getElementsByTag("td"); logger.severe("td count=" + fields.size()); if (fields.size() == 0) continue; for (int f=0; f