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];
int hprice[]=new int[100];
int lprice[]=new int[100];
int cprice[]=new int[100];
int volume[]=new int[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=TYO:7203";
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]);
}
}
int makeprice(String str){
int p,m1;
p=ckc(str);
m1=0;
if(p==1)m1=make1(str);
if(p==2)m1=make2(str);
if(p==0)m1=make0(str);
return m1;
}
int ckc(String str){
int px;
String[] z=str.split(",");
px=z.length;
return px-1;
}
int make0(String str){
double a;
int b;
a=Double.parseDouble(str);
b=(int)a;
return b;
}
int make2(String str){
double a,b,c,d;
int e;
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;
e=(int)d;
return e;
}
int make1(String str){
double a,b,c;
int d;
String[] y=str.split(",");
a=Double.parseDouble(y[0]);
b=Double.parseDouble(y[1]);
c=1000*a+b;
d=(int)c;
return d;
}
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:47