import java.io.*;
import java.net.*;
class game0320{
int s,sx;
int mode;
String urlx;
String bun,chbun;
int x[]=new int[1000];
int y[]=new int[1000];
int item1[]=new int[100];
int item2[]=new int[100];
String[] title=new String[100];
String[] link=new String[100];
String[] date=new String[100];
String[] des=new String[100];
int title1[]=new int[100];
int title2[]=new int[100];
int date1[]=new int[100];
int date2[]=new int[100];
int des1[]=new int[100];
int des2[]=new int[100];
int link1[]=new int[100];
int link2[]=new int[100];
String xml[]=new String[1000];
int z;
int xmlnumber;
int p1,p2,x1,x2;
int articlenumber;
String cc;
String str;
public static void main(String [] args) {
game0320 f=new game0320();
}
game0320(){
urlx="http://www.google.com/finance/company_news?q=NASDAQ:GOOG&output=rss";
getdata(urlx);
s=1;
mode=0;
z=bun.indexOf("<");
x[1]=z;
while(mode<50){
z=bun.indexOf("<",z+1);
if(z>-1)s=s+1;
if(z>-1)x[s]=z;
if(z<0)mode=100;
}
s=1;
mode=0;
z=bun.indexOf(">");
y[1]=z;
while(mode<50){
z=bun.indexOf(">",z+1);
if(z>-1)s=s+1;
if(z>-1)y[s]=z;
if(z<0)mode=100;
}
xmlnumber=s;
for(s=1;s<xmlnumber+1;s++){
p1=x[s];
p2=y[s];
xml[s]=bun.substring(p1+1,p2);
}
sx=0;
for (s=1;s<xmlnumber+1;s++){
p1=xml[s].indexOf("item");
p2=xml[s].indexOf("/item");
if(p2>-1)p1=-999;
if(p1>-1)sx=sx+1;
if(p1>-1)item1[sx]=s;
if(p2>-1)item2[sx]=s;
}
articlenumber=sx;
for (s=1;s<articlenumber+1;s++){
p1=item1[s];
p2=item2[s];
for(sx=p1;sx<p2;sx++){
x1=xml[sx].indexOf("title");
x2=xml[sx].indexOf("/title");
if(x2>-1)x1=-999;
if(x1>-1)title1[s]=sx;
if(x2>-1)title2[s]=sx;
}
}
for (s=1;s<articlenumber+1;s++){
p1=item1[s];
p2=item2[s];
for(sx=p1;sx<p2;sx++){
x1=xml[sx].indexOf("pubDate");
x2=xml[sx].indexOf("/pubDate");
if(x2>-1)x1=-999;
if(x1>-1)date1[s]=sx;
if(x2>-1)date2[s]=sx;
}
}
for (s=1;s<articlenumber+1;s++){
p1=item1[s];
p2=item2[s];
for(sx=p1;sx<p2;sx++){
x1=xml[sx].indexOf("description");
x2=xml[sx].indexOf("/description");
if(x2>-1)x1=-999;
if(x1>-1)des1[s]=sx;
if(x2>-1)des2[s]=sx;
}
}
for (s=1;s<articlenumber+1;s++){
p1=item1[s];
p2=item2[s];
for(sx=p1;sx<p2;sx++){
x1=xml[sx].indexOf("link");
x2=xml[sx].indexOf("/link");
if(x2>-1)x1=-999;
if(x1>-1)link1[s]=sx;
if(x2>-1)link2[s]=sx;
}
}
for(s=1;s<articlenumber+1;s++){
p1=y[title1[s]];
p2=x[title2[s]];
title[s]=bun.substring(p1+1,p2);
}
for(s=1;s<articlenumber+1;s++){
p1=y[des1[s]];
p2=x[des2[s]];
des[s]=bun.substring(p1+1,p2);
}
for(s=1;s<articlenumber+1;s++){
p1=y[date1[s]];
p2=x[date2[s]];
date[s]=bun.substring(p1+1,p2);
}
for(s=1;s<articlenumber+1;s++){
p1=y[link1[s]];
p2=x[link2[s]];
link[s]=bun.substring(p1+1,p2);
}
for(s=1;s<articlenumber+1;s++){
des[s]=rev(des[s]);
}
for(s=1;s<articlenumber+1;s++){
System.out.println(title[s]);
System.out.println(date[s]);
System.out.println(link[s]);
System.out.println(des[s]);
}
}
String rev(String str){
String z,str1,str2,str3,str4;
str1="<";
str2="<";
str3=">";
str4=">";
z=str.replace(str2,str1);
z=z.replace(str4,str3);
int p;
p=check(z);
while(p>50){
z=play(z);
p=check(z);
}
return z;
}
int check(String str){
int p,h,p1,p2;
String str1,str2;
str1="<";
str2=">";
p=100;
p1=str.indexOf(str1);
p2=str.indexOf(str2);
h=0;
if(p1<0)p=0;
if(p2<0)p=0;
return p;
}
String play(String str){
int p1,p2,px,zlong;
String r2[]=new String[100];
String str1,str2;
String x1,x2;
str1="<";
str2=">";
zlong=str.length();
p1=str.indexOf(str1);
p2=str.indexOf(str2);
x1="";
x1=str.substring(0,p1);
x2=str.substring(p2+1,zlong);
return x1+x2;
}
void getdata(String name){
int num;
int n;
String data[]=new String[10000];
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); }
bun="";
for (n=0;n<num;n++){
bun=bun+data[n];
}
}
}
最終更新:2011年03月31日 23:48