⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 stockreader.java

📁 股票信息采集源码
💻 JAVA
字号:
/**
 * 
 */
package cn.com.lucre.stock.tools;

/**
 * @author ABE
 *
 */
import java.io.*;
import java.net.*;

import cn.com.lucre.stock.db.StockDB;
import cn.com.lucre.stock.model.Stock;

public class StockReader {
	String sql="";
	StockDB db;
	Stock stock;
	public void Reader(String argv,String area) throws Exception{
		System.out.println("-----"+argv+"---------"+area+"-------------");
		stock=new Stock();
		String quoteFormat = "&f=sl1d1t1c1ohgv&e=.csv";//"&f=slc1wop";".SS&f=sl1d1t1c1ohgv&e=.csv";
		if(area.equals("2")){
			quoteFormat=".SS"+quoteFormat;
		}else if(area.equals("1")){
			quoteFormat=".SZ"+quoteFormat;
		}
//http://finance.yahoo.com/d/quotes.csv?s=600000.SS&f=sl1d1t1c1ohgv&e=.csv沪证
//http://finance.yahoo.com/d/quotes.csv?s=399481.SZ&f=sl1d1t1c1ohgv&e=.csv深证
        URL url = new URL("http://quote.yahoo.com/d/quotes.csv?");

        URLConnection connection = url.openConnection();
        connection.setDoOutput(true);

        PrintWriter out = new PrintWriter(connection.getOutputStream());
        out.println("s=" + argv + quoteFormat);
        out.close();

        BufferedReader in = new BufferedReader(
                                               new InputStreamReader(connection.getInputStream()));

        String line = in.readLine();

        /* DEBUG
           while ((line = in.readLine()) != null) {
           System.out.println("Got: "+ line);
           }
        */
        in.close();
        if(line.length()>0){
        	
        	stock.parse(line);
        	writer(argv);
        /*System.out.println("Name: "+ Stock.getName(line));
        System.out.println("Price: "+ Stock.getPrice(line));
        System.out.println("Date: "+ Stock.getDate(line));*/
        }else{
        	System.out.println("Not get content!");
        }
	}
    public void writer(String code){
//   name+"---"+price+"-------"+date+"---"+time+"-----"+fluctuate+"------"+open_quotation+"----"+max_price+"----"+min_price+"--------"+quantity);
    	if(stock.quantity!=null&&stock.time!=null&&stock.date!=null){
    	db=new StockDB();
    	db.addStockMeg(code,stock.price,stock.date,stock.time,stock.fluctuate,stock.open_quotation,stock.max_price,stock.min_price,stock.quantity);
    	}
    }
    public static void main(String argv[]) throws Exception {
        String[] code={"600690",
        		       "600691",
        		       "600692",
        		       "600693",
        		       "600694"
        		            };
        StockReader reader=new StockReader();
        for(int i=0;i<code.length;i++)
        reader.Reader(code[i],"2");
    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -