アットウィキロゴ

xxs

import java.io.*;
import java.net.*;

class game0320{

int s;
String str,urlx;
String bun,chbun;    
String[] article=new String[100];
int articlenumber;

public static void main(String [] args) {
        game0320 f=new game0320();
            }

game0320(){

urlx="http://news.google.com/news?hl=en&q=android&um=1&ie=UTF-8&output=rss";

getdata(urlx);

makearticle(bun);

for(s=1;s<articlenumber+1;s++){
str=makedes(article[s]);
System.out.println(rev(str));
}


}

String rev(String str){
String z1;
z1=str;
z1=z1.replace("&lt;","<");
z1=z1.replace("&gt;",">");
int p;
p=check(z1);
while(p>50){
z1=play(z1);
p=check(z1);
}
return z1;
}

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="";
if(p1>0)x1=str.substring(0,p1-1);
x2=str.substring(p2+1,zlong);
return x1+x2;
}





String maketitle(String str){
String str1,str2;
String z;
int x1,x2;
str1="<title>";
str2="</title>";
x1=str.indexOf(str1);
x2=str.indexOf(str2);
z=str.substring(x1+7,x2);
return z;
}

String makedes(String str){
String str1,str2;
String z;
int x1,x2;
str1="<description>";
str2="</description>";
x1=str.indexOf(str1);
x2=str.indexOf(str2);
z=str.substring(x1+13,x2);
return z;
}


void makearticle(String str){
String str1,str2;
String z,z1,z2;
int p,zlong;
int x1,x2;
int s;
z=str;
s=0;
str1="<item>";
str2="</item>";
p=100;
x1=0;
x2=0;
z1="";
z2="";
while(p>-1){
p=z.indexOf(str1);
zlong=z.length();
if(p>-1)x1=z.indexOf(str1);
if(p>-1)x2=z.indexOf(str2);
if(p>-1)z1=z.substring(x1+6,x2);
if(p>-1)z2=z.substring(x2+6,zlong);
if(p>-1)s=s+1;
if(p>-1)article[s]=z1;
if(p>-1)z=z2;
}
articlenumber=s;
}



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日 17:37