Sina stock Network Interface ps: I wrote the first simplest web crawler o (^) o, Web interface Crawler
1 package com.down.edu; 2 3 import java.io.BufferedReader; 4 import java.io.InputStream; 5 import java.io.InputStreamReader; 6 import java.net.HttpURLConnection; 7 import java.net.URL; 8 9 public class DOWNDATA {10 public String data="";11 12 public DOWNDATA(String code)13 {14 String Httpurl="http://hq.sinajs.cn/list=sh";15 StringBuffer content=new StringBuffer();16 try{17 URL httpURL=new URL(Httpurl+code);18 HttpURLConnection connection=(HttpURLConnection)httpURL.openConnection();19 connection.connect();20 InputStream is=connection.getInputStream();21 BufferedReader br=new BufferedReader(new InputStreamReader(is));22 String str="";23 while((str=br.readLine())!=null){24 content.append(str);25 }26 27 br.close();28 is.close();29 }catch(Exception e){30 31 }32 String cont=content.toString();33 data=cont.replace("var hq_str_sh"+code+"=\"", "").replace(",00\";", "");34 35 }36 37 }
This part is the most important, but I also feel that there is nothing to talk about. It is also a comma-separated character, and then the unnecessary part is deleted and finally presented in the interface ~ See:
Package com.ui.edu; import com.down.edu. *; import java. awt. *; import java. awt. event. actionEvent; import java. awt. event. actionListener; import java. util. vector; import javax. swing. *; import javax. swing. table. defaultTableModel; import com.down.edu. *; public class UI implements ActionListener {/*** @ param solitary defeat * mailbox hcareking@163.com * function: stock offline analysis system */JFrame f; JTextField jtf; JTextArea jta; JButton jb; JPanel Jp; DefaultTableModel atm = null; Vector vDate = new Vector (); Vector vName = new Vector (); JTable table = null; JScrollPane sPane = null; public static void main (String [] args) {// TODO Auto-generated method stub UI ui = new UI ();} public UI () {// element attribute f = new JFrame ("stock offline analysis system"); f. setLayout (new BorderLayout (); jp = new JPanel (); jp. setLayout (new FlowLayout (); jtf = new JTextField (40); jtf. add ActionListener (this); vName. add ("stock name"); vName. add (""); vName. add ("Yesterday's closing price"); vName. add ("current price"); vName. add ("highest price today"); vName. add ("lowest price today"); vName. add ("bidding price"); vName. add ("competitive price"); vName. add ("number of shares sold/100"); vName. add ("deal amount/"); atm = new DefaultTableModel (vDate, vName); Object [] [] data ={}; table = new JTable (atm); table. setSelectionMode (ListSelectionModel. SINGLE_SELECTION );//???? Table. setPreferredScrollableViewportSize (new Dimension (600, 80); Font x = new Font ("seril", 0, 12); table. setFont (x); JScrollPane scrollPane = new JScrollPane (table); table. setFillsViewportHeight (true); table. updateUI (); jb = new JButton ("Submit"); jb. addActionListener (this); // Add element f. getContentPane (). add (scrollPane, BorderLayout. CENTER); jp. add (jtf); jp. add (jb); f. add (jp, BorderLayout. NORTH); // framework setting f. setSize (1000,600); Dimension screenSize = Toolkit. getdefatooltoolkit (). getScreenSize (); f. setLocation (int) screenSize. getWidth ()/2-500, (int) screenSize. getHeight ()/2-300); f. setVisible (true); f. setResizable (false); f. setdefaclocloseoperation (JFrame. EXIT_ON_CLOSE);} @ Override public void actionreceivmed (ActionEvent e) {// TODO Auto-generated method stub if (e. getActionCommand (). equals ("Submit") {System. out. println (jtf. getText (); DOWNDATA downdata = new DOWNDATA (jtf. getText (); addDate (downdata. data) ;}} public void addDate (String data) {Vector vTmp = new Vector (); String split [] = data. split (","); for (int a = 0; a <= 9; a ++) {System. out. println (split [a]); vTmp. add (split [a]);} vDate. add (vTmp); table. updateUI ();}}
In short, it's very easy. Let's give it a reference for beginners. Then, the first step of the long journey will be stronger ~, Everything will be fine. I am not compromising my life, but waiting for the dawn.