java 股票历史数据_获取股票的历史数据

该Java程序从新浪财经获取指定股票的历史数据。通过Jsoup库解析HTML页面,提取表格中的时间、开盘价、最高价、收盘价、最低价、成交量和成交金额等信息,并将数据存储为HisStockData对象进行展示。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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());

}

}

}

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值