50,531
社区成员
发帖
与我相关
我的任务
分享
Map<String,String> param = new HashMap<String,String>();
param.put("http://www.travelco.com/searchDepartureAirport", "哈尔滨");//出发
param.put("http://www.travelco.com/searchArrivalAirport", "北京");//到站
param.put("http://www.travelco.com/searchDepartureTime", "2012-01-29");//日期
param.put("searchType", "OneWayFlight");
Document doc = Jsoup.connect("http://flight.qunar.com/twell/longwell").data(param).get();
String result = doc.text();
result = result.substring(1, result.length()-1);
System.out.println(result);
Gson gson = new Gson();
HashMap map = gson.fromJson(result, HashMap.class);
Map priceInfo = (Map)((Map)map.get("oneway_data")).get("priceInfo");
for(Object tmp:priceInfo.keySet()){
System.out.println(tmp + " 最低票价: "+((Map)priceInfo.get(tmp)).get("lowpr"));
}
WebClient w = new WebClient();
w.setJavaScriptEnabled(true);
HtmlPage page = (HtmlPage) w.getPage("http://flight.qunar.com/site/oneway_list.htm?searchDepartureAirport=%E5%93%88%E5%B0%94%E6%BB%A8&searchArrivalAirport=%E5%8C%97%E4%BA%AC&searchDepartureTime=2012-01-29&searchArrivalTime=2012-01-29&nextNDays=0&startSearch=true&from=fi_ont_search");
List<DomNode> nodes = (List<DomNode>) page.getByXPath("/html/body/div[3]/div[4]/div/div[5]");
//Thread.sleep(10000);
for (DomNode node : nodes) {
System.out.println(node.asText());
}