大家好,又见面了,我是你们的朋友全栈君。
packagecom.xiaole.stock;importjava.util.ArrayList;importjava.util.List;importorg.jsoup.Jsoup;importorg.jsoup.nodes.Document;importorg.jsoup.nodes.Element;importorg.jsoup.select.Elements;public classGetHistoryData {public static voidmain(String[] args) {
String url= “http://money.finance.sina.com.cn/corp/go.php/vMS_MarketHistory/stockid/000952.phtml?year=2014&jidu=3”;
System.out.println(url);
String msg= HttpService.sendHttpMsg(url, false,”gbk”,null);
Document document=Jsoup.parse(msg);
Elements stockdatas= document.select(“table#FundHoldSharesTable”).select(“tr”);for(Element e : stockdatas){
String time;doubleopenPrice;doublehighPrice;doubleendPrice;doublelowPrice;intdealCount;intdealAmount;
Element tmp= e.select(“td”).select(“a”).first();if(tmp != null){
List infoList = new ArrayList();
Elements infos= e.select(“td”);for(Element info : infos){
String tmpMsg=info.text();
infoList.add(tmpMsg);
}
HisStockData hisData= newHisStockData();
time= infoList.get(0);
openPrice= Double.parseDouble(infoList.get(1));
highPrice= Double.parseDouble(infoList.get(2));
endPrice= Double.parseDouble(infoList.get(3));
lowPrice= Double.parseDouble(infoList.get(4));
dealCount= Integer.parseInt(infoList.get(5));
dealAmount= Integer.parseInt(infoList.get(6));
hisData.setTime(time);
hisData.setOpenPrice(openPrice);
hisData.setHighPrice(highPrice);
hisData.setEndPrice(endPrice);
hisData.setLowPrice(lowPrice);
hisData.setDealAmount(dealAmount);
hisData.setDealCount(dealCount);
System.out.println(hisData.toString());
}
}
}
}
发布者:全栈程序员-用户IM,转载请注明出处:https://javaforall.cn/152708.html原文链接:https://javaforall.cn
【正版授权,激活自己账号】: Jetbrains全家桶Ide使用,1年售后保障,每天仅需1毛
【官方授权 正版激活】: 官方授权 正版激活 支持Jetbrains家族下所有IDE 使用个人JB账号...