package diet;
import tool.readfile;
import java.io.*;
import java.io.File;
public class pro {
int s,datanumber;
String[] data=new String[5000];
String[][] namex=new String[500][100];
String[][] age=new String[500][100];
String[][] party=new String[500][100];
String[][] point=new String[500][100];
int number;
String[] lab=new String[5000];
int[] numberx=new int[5000];
String[][] wn=new String[500][100];
String[][] pww=new String[500][100];
public static void main(String[] args) {
pro t=new pro();
}
pro(){
File f=new File("data");
String[] ff=f.list();
int den;
for(den=0;den<ff.length;den++){
readfile sub3=new readfile();
sub3.makedata("data/"+ff[den],"UTF-8");
data=sub3.data;
datanumber=sub3.datanumber;
String p5=data[1];
String[] x1=p5.split("</tr>");
int sx=0;
for(s=1;s<x1.length-1;s++){
sx=sx+1;
lab[sx]=x1[s];
}
number=sx;
for(s=1;s<number+1;s++){
int p1=lab[s].indexOf("title");
p1=lab[s].indexOf(">",p1);
int p2=lab[s].indexOf("<",p1);
lab[s]=lab[s].substring(p1+1,p2);
}
int tr;
for(tr=1;tr<number+1;tr++){
String str=""+data[tr+1];
String[] x2=str.split("</tr>");
numberx[tr]=x2.length-2;
for(s=1;s<x2.length-1;s++){
String[] x3=x2[s].split("</td>");
for(sx=0;sx<x3.length;sx++){
if(sx==1)namex[tr][s]=x3[sx];
if(sx==2)age[tr][s]=clean_str(x3[sx]);
if(sx==3)party[tr][s]=x3[sx];
if(sx==5)point[tr][s]=clean_str(x3[sx]);
}
}
}
for(s=1;s<number+1;s++){
for(sx=1;sx<numberx[s]+1;sx++){
int p1=namex[s][sx].indexOf("/wiki/");
int p2=namex[s][sx].indexOf("\"",p1);
wn[s][sx]="";
if(p1>-1)wn[s][sx]=namex[s][sx].substring(p1,p2);
namex[s][sx]=clean_str(namex[s][sx]);
}
}
for(s=1;s<number+1;s++){
for(sx=1;sx<numberx[s]+1;sx++){
int p1=party[s][sx].indexOf("/wiki/");
int p2=party[s][sx].indexOf("\"",p1);
pww[s][sx]="";
if(p1>-1)pww[s][sx]=party[s][sx].substring(p1,p2);
party[s][sx]=clean_str(party[s][sx]);
}
}
writexml("gdata/"+ff[den]);
}
}
void writexml(String file){
int s,sx;
try{
PrintWriter pw = new PrintWriter (new BufferedWriter(new FileWriter(file)));
for(s=1;s<number+1;s++){
for(sx=1;sx<numberx[s]+1;sx++){
pw.print(lab[number-s+1]);
pw.print(",");
pw.print(namex[s][sx]);
pw.print(",");
pw.print(wn[s][sx]);
pw.print(",");
pw.print(party[s][sx]);
pw.print(",");
pw.print(pww[s][sx]);
pw.print(",");
pw.print(point[s][sx].replace(",",""));
pw.print(",");
pw.println(age[s][sx]);
}
}
System.out.println("ファイルに書きこみました。");
pw.close();
} catch(IOException ep){ System.out.println("入出力エラーです。"); }
}
String clean_str(String str){
int kk;
String sp=str;
for(kk=1;kk<15;kk++){
sp=fresh(sp);
}
return sp;
}
String fresh(String strstr){
strstr=""+strstr;
int p1=strstr.indexOf("<");
int p2=-1;
if(p1>-1)p2=strstr.indexOf(">",p1);
String k="";
if(p2>-1)k=strstr.substring(p1,p2)+">";
String strxp=strstr.replace(k,"");
return strxp;
}
}
最終更新:2017年10月12日 10:11