[자바] 현재 주식 정보 획득

4267 단어
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)
            System.out.println(ind[i] + ": " +tcs[i]);     
    }
}

 
다음으로 전송:https://www.cnblogs.com/tiandsp/p/7467848.html

좋은 웹페이지 즐겨찾기