import java.net.*;
import java.io.*;
class game0505{
String data[]=new String[1000];
String data1[]=new String[1000];
int point[]=new int[1000];
String date[]=new String[100];
double oprice[]=new double[100];
double hprice[]=new double[100];
double lprice[]=new double[100];
double cprice[]=new double[100];
double volume[]=new double[100];
int num,n,m;
String x;
public static void main(String [] args) {
game0505 test=new game0505();
}
game0505(){
String urlx;
urlx="http://www.google.com/finance/historical?q=NYSE:HMC";
getdata(urlx);
String str1;
str1="<td class=";
m=0;
for(n=0;n<num;n++){
if(data[n].indexOf(str1)>-1)data1[m]=data[n];
if(data[n].indexOf(str1)>-1)m=m+1;
}
num=m;
m=0;
for(n=0;n<num;n++){
if(data1[n].indexOf("lm")>-1)point[m]=n;
if(data1[n].indexOf("lm")>-1)m=m+1;
}
num=m;
for (n=0;n<num;n++){
m=point[n];
String[] x1=data1[m].split(">");
date[n]=x1[1];
String[] x2=data1[m+1].split(">");
oprice[n]=makeprice(x2[1]);
String[] x3=data1[m+2].split(">");
hprice[n]=makeprice(x3[1]);
String[] x4=data1[m+3].split(">");
lprice[n]=makeprice(x4[1]);
String[] x5=data1[m+4].split(">");
cprice[n]=makeprice(x5[1]);
String[] x6=data1[m+5].split(">");
volume[n]=makeprice(x6[1]);
}
for (n=0;n<num;n++){
System.out.println(lprice[n]);
}
}
double makeprice(String str){
int p;
double mx;
p=ckc(str);
mx=0;
if(p==1)mx=make1(str);
if(p==2)mx=make2(str);
if(p==0)mx=make0(str);
return mx;
}
int ckc(String str){
int px;
String[] z=str.split(",");
px=z.length;
return px-1;
}
double make0(String str){
double a;
a=Double.parseDouble(str);
return a;
}
double make2(String str){
double a,b,c,d;
String[] y=str.split(",");
a=Double.parseDouble(y[0]);
b=Double.parseDouble(y[1]);
c=Double.parseDouble(y[2]);;
d=1000*1000*a+1000*b+c;
return d;
}
double make1(String str){
double a,b,c;
String[] y=str.split(",");
a=Double.parseDouble(y[0]);
b=Double.parseDouble(y[1]);
c=1000*a+b;
return c;
}
void getdata(String name){
int n;
num=0;
try{
URL url = new URL(name);
HttpURLConnection con = (HttpURLConnection)url.openConnection();
con.setRequestMethod("GET");
con.connect();
BufferedReader reader =
new BufferedReader(new InputStreamReader(con.getInputStream(),"UTF-8"));
n=0;
while (true){
String line = reader.readLine();
if ( line == null ){
break;
}
data[n]=line;
n=n+1;
num=n;
}
reader.close();
con.disconnect();
}
catch(Exception e) { System.err.println(e); }
}
}
最終更新:2011年03月28日 13:59