アットウィキロゴ

しゅゆ

package base;
 
import java.io.BufferedWriter;
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;
import tool.*;
 
public class pro {
 
    int s,datanumber;
    String[] data=new String[5000];
       String[] credit=new String[5000];     
    int number;
int[] point=new int[500];
String[] link=new String[50000];
String[] name=new String[50000];
String[] year=new String[50000];
 
  String[][] a=new String[500][100];
   String[] subdata=new String[50000];
    public static void main(String[] args) {
        pro t=new pro();
    }
    pro(){
 
 
        readfile sub6=new readfile();
         sub6.makedata("data.csv","UTF-8");
   data=sub6.data;
   datanumber=sub6.datanumber;
 
   for(s=2;s<datanumber+1;s++){
   String[] x=data[s].split(",");
   link[s]="";
   if(x.length>7)link[s]=x[7];
  year[s]=x[1];
  name[s]=x[4];
   System.out.println(name[s]);    
   }
 
   int de=datanumber;
   int tr;
 
   for(tr=2;tr<de+1;tr++){     
 
 String urlx="https://ja.wikipedia.org/"+link[tr];
 
 if(link[tr].length()>4){
 
   getdata sub=new getdata();
   sub.makedata(urlx,"UTF-8");
   data=sub.data;
   datanumber=sub.datanumber;
 
   int s1=0;
   for(s=1;s<datanumber+1;s++){
   if(data[s].indexOf("年度別打撃成績")>-1)s1=s;    
   }
 
   if(s1>10){
 
   int s2=0;
   for(s=s1+1;s<datanumber+1;s++){
    int h=0;
    if(data[s].indexOf("</tab")>-1)h=h+1;
    if(s2==0)h=h+1;
    if(h==2)s2=s; 
    }
 
   String str="";
   for(s=s1+1;s<s2;s++){
     str=str+data[s];
    }
 
   str=str.replace("th","td");
 
   String[] x=str.split("</tr>");
   int sx;
   String[] yy=x[0].split("</td>");
   for(s=0;s<yy.length;s++){
   credit[s]=change(yy[s]);    
   }
 
 
   number=yy.length;
 
    System.out.println(number);
 
  for(s=1;s<x.length;s++){
  String[] y=x[s].split("</td>");
  for(sx=0;sx<y.length;sx++){
  a[s][sx]=change(y[sx]); 
  }
  int nn=y.length;
  point[s]=nn;
 
  } 
 
  String te="";
  int tx=0;
  for(s=1;s<x.length;s++){
 if(point[s]==number)te=a[s][1];
  for(sx=2;sx<number;sx++){
  s1=sx;    
  if(point[s]<number)s1=sx-1;
  tx=tx+1;
  subdata[tx]=a[s][0]+","+te+","+credit[sx]+","+a[s][s1];
  }   
  }
 
 datanumber=tx;       
 
 
 String namex=name[tr]+"("+year[tr]+")";
 
 writexml("bat/"+namex+".txt");       
   }
   }
 
   }
 
 
    }
    void writexml(String file){ 
 
    int s,sx;
 
try{ 
PrintWriter pw = new PrintWriter (new BufferedWriter(new FileWriter(file))); 
 
for(s=1;s<datanumber+1;s++){    
pw.println(subdata[s]);  
}
 
 
System.out.println("ファイルに書きこみました。"); 
pw.close(); 
} catch(IOException ep){ System.out.println("入出力エラーです。"); } 
 
 
} 
      String change(String str){
 
        int n;
        for(n=1;n<15;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年12月17日 04:19