首页 > 代码库 > 【Java】得到当前股票信息
【Java】得到当前股票信息
import java.io.BufferedReader; import java.io.InputStreamReader; import java.net.HttpURLConnection; import java.net.URL; public class MainProcess { public static String getHtmlConentByUrl(String ssourl) { try { URL url = new URL(ssourl); HttpURLConnection con = (HttpURLConnection) url.openConnection(); con.setInstanceFollowRedirects(false); con.setUseCaches(false); con.setAllowUserInteraction(false); con.connect(); StringBuffer sb = new StringBuffer(); String line = ""; BufferedReader URLinput = new BufferedReader(new InputStreamReader( con.getInputStream())); while ((line = URLinput.readLine()) != null) { sb.append(line); } con.disconnect(); return sb.toString().toLowerCase(); } catch (Exception e) { return null; } } public static void main(String[] args) { String[] ind = {"股票名称","今日开盘价","昨日收盘价","当前价格","今日最高价","今日最低价","买一报价","卖一报价","成交股数", "成交金额","买一股数","买一报价","买二股数","买二报价","买三股数","买三报价","买四股数","买四报价","买五股数","买五报价", "卖一股数","卖一报价","卖二股数","卖二报价","卖三股数","卖三报价","卖四股数","卖四报价","卖五股数","卖五报价","当前日期","当前时间"}; String ss = getHtmlConentByUrl("http://hq.sinajs.cn/list=sh600066");//你要访问的页面 String[] fcs = ss.split("\""); //按"号分割字符 String scs = fcs[1]; String[] tcs = scs.split(","); //按,号分割字符 for(int i=0;i<tcs.length-1;i++) System.out.println(ind[i] + ": " +tcs[i]); } }
【Java】得到当前股票信息
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。