package d;
import tool.*;
import java.io.*;
public class pro {
int s,datanumber;
String[] data=new String[5000];
String[] title=new String[5000];
String[] sta=new String[5000];
String[] time=new String[5000];
String[][] rate=new String[5000][30];
String[] date=new String[5000];
String[] avg=new String[5000];
int number;
int yy,mm;
public static void main(String[] args) {
pro tes=new pro();
}
pro(){
int m;
int tr=0;
for(yy=3;yy<16;yy++){
for(m=1;m<5;m++){
mm=3*m-2;
String strx=""+yy;
if(yy<10)strx="0"+yy;
if(mm>9)strx=strx+mm;
if(mm<10)strx=strx+"0"+mm;
String urlx="http://artv.info/ar"+strx+".html";
getdata sub2=new getdata();
sub2.makedata(urlx,"EUC-JP");
data=sub2.data;
datanumber=sub2.datanumber;
int s1=0;
int s2=0;
for(s=1;s<datanumber+1;s++){
if(data[s].indexOf("simpleArTb")>-1)s1=s;
}
int h;
for(s=s1;s<datanumber+1;s++){
h=0;
if(data[s].indexOf("</table")>-1)h=h+1;
if(s2==0)h=h+1;
if(h==2)s2=s;
}
String str="";
for(s=s1;s<s2;s++){
str=str+data[s];
}
String[] x=str.split("</tr>");
int sx;
for(s=1;s<x.length;s++){
String[] y=x[s].split("</td>");
for(sx=0;sx<y.length;sx++){
if(sx==1)sta[s]=change(y[sx]);
if(sx==2)time[s]=change(y[sx]);
if(sx==3)title[s]=change(y[sx]);
if(sx>3)rate[s][sx-3]=change(y[sx]);
if(sx==y.length-2)avg[s]=change(y[sx]);
}
}
number=x.length-1;
tr=tr+1;
writexml("data/"+tr+".txt");
}
}
}
void writexml(String file){
int s,sx;
try{
PrintWriter pw = new PrintWriter (new BufferedWriter(new FileWriter(file)));
for(s=1;s<number+1;s++){
pw.print("<year>");
pw.print(yy+2000);
pw.print("</year>");
pw.print("<month>");
pw.print(mm);
pw.print("</month>");
pw.print("<title>");
pw.print(title[s]);
pw.print("</title>");
pw.print("<sta>");
pw.print(sta[s]);
pw.print("</sta>");
pw.print("<time>");
pw.print(time[s]);
pw.print("</time>");
for(sx=1;sx<11;sx++){
pw.print("<rate");
pw.print(sx);
pw.print(">");
pw.print(rate[s][sx]);
pw.print("</rate");
pw.print(sx);
pw.print(">");
}
pw.print("<avg>");
pw.print(avg[s]);
pw.println("</avg>");
}
System.out.println("ファイルに書きこみました。");
pw.close();
} catch(IOException ep){ System.out.println("入出力エラーです。"); }
}
String change(String str){
int n;
for(n=1;n<11;n++){
str=rev(str);
}
str=str.replace(" ","");
return str;
}
String rev(String str){
if(str==null)str="";
int p1=str.indexOf("<");
int p2=str.indexOf(">",p1);
String strx="";
if(p2>-1)strx=str.substring(p1,p2+1);
str=str.replace(strx,"");
return str;
}
}
最終更新:2016年02月29日 16:40