import java.net.*;
import java.io.*;
class yahooac{
String bun;
String[] article=new String[1000];
String[] title=new String[1000];
String[] link=new String[1000];
String[] pubdate=new String[1000];
String[] des=new String[1000];
int[] year=new int[1000];
int[] day=new int[1000];
String[] month=new String[1000];
int s;
int articlenumber;
void makedata(String urlx){
getdata(urlx);
makearticle();
for(s=1;s<articlenumber+1;s++){
title[s]=makeitem(article[s],"title");
pubdate[s]=makeitem(article[s],"pubDate");
link[s]=makeitem(article[s],"link");
des[s]=makeitem(article[s],"description");
}
for(s=1;s<articlenumber+1;s++){
makedate(s,pubdate[s]);
}
}
String makeitem(String str,String cc){
int x1,x2,x3;
String x4;
String str1,str2;
str1="<" + cc + ">";
str2="</" + cc + ">";
x1=str.lastIndexOf(str1);
x3=str1.length();
x2=str.indexOf(str2);
x4=str.substring(x1+x3,x2);
return x4;
}
void makedate(int s,String str){
String d1,d2,d3,d4;
int z3,z4;
d1=str.substring(8,11);
d2=str.substring(12,16);
d3=str.substring(5,6);
d4=str.substring(6,7);
month[s]=d1;
year[s]=Integer.parseInt(d2);
z3=Integer.parseInt(d3);
z4=Integer.parseInt(d4);
day[s]=10*z3+z4;
}
void makearticle(){
int s;
String[] x=bun.split("<item>");
articlenumber=x.length-1;
for (s=1;s<articlenumber+1;s++){
String[] y=x[s].split("</item>");
article[s]=y[0];
}
}
void getdata(String urlx){
int n;
String data[]=new String[1000];
int getnumber;
getnumber=0;
try{
URL url = new URL(urlx);
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;
getnumber=n;
}
reader.close();
con.disconnect();
}
catch(Exception e) { System.err.println(e); }
bun="";
for(n=0;n<getnumber;n++){
bun=bun+data[n];
}
}
}
最終更新:2011年03月30日 20:01