7 |
import java.util.Collections; |
import java.util.Collections; |
8 |
import java.util.List; |
import java.util.List; |
9 |
|
|
10 |
|
import com.gargoylesoftware.htmlunit.ProxyConfig; |
11 |
import com.gargoylesoftware.htmlunit.WebClient; |
import com.gargoylesoftware.htmlunit.WebClient; |
12 |
import com.gargoylesoftware.htmlunit.html.DomNodeList; |
import com.gargoylesoftware.htmlunit.html.DomNodeList; |
13 |
import com.gargoylesoftware.htmlunit.html.HtmlElement; |
import com.gargoylesoftware.htmlunit.html.HtmlElement; |
61 |
|
|
62 |
final WebClient webClient = new WebClient(); |
final WebClient webClient = new WebClient(); |
63 |
webClient.setTimeout(1000); |
webClient.setTimeout(1000); |
64 |
webClient.setJavaScriptEnabled(false); |
webClient.setJavaScriptEnabled(false); |
65 |
|
|
66 |
|
|
67 |
final HtmlPage page = webClient.getPage("http://www.bane.dk/visStation.asp?ArtikelID=4275&W=" + type + "&S=" + stationcode); |
final HtmlPage page = webClient.getPage("http://www.bane.dk/visStation.asp?ArtikelID=4275&W=" + type + "&S=" + stationcode); |
68 |
|
|
97 |
String status = fields.get(6).asText(); |
String status = fields.get(6).asText(); |
98 |
departure.setStatus(status); |
departure.setStatus(status); |
99 |
|
|
100 |
String note = fields.get(7).asText(); |
String note = extractNote( fields.get(7) ); |
101 |
departure.setNote(note); |
departure.setNote(note); |
102 |
|
|
103 |
departureList.add(departure); |
departureList.add(departure); |
125 |
return updated; |
return updated; |
126 |
} |
} |
127 |
|
|
128 |
|
private String extractNote(HtmlElement noteTd) { |
129 |
|
String note = noteTd.asText().trim(); |
130 |
|
|
131 |
|
List<HtmlElement> elems = noteTd.getElementsByAttribute("span", "class", "bemtype"); |
132 |
|
if (elems.size() > 0 && note.charAt(note.length()-1) == 'i') |
133 |
|
note = note.substring(0,note.length() -1 ); |
134 |
|
|
135 |
|
return note; |
136 |
|
} |
137 |
|
|
138 |
//test |
//test |
139 |
public static void main(String args[]) throws Exception{ |
public static void main(String args[]) throws Exception{ |
140 |
DepartureFetcher f = new DepartureFetcher(); |
DepartureFetcher f = new DepartureFetcher(); |