package wiki;
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[][] a=new String[500][100];
String[] subdata=new String[50000];
public static void main(String[] args) {
pro t=new pro();
}
pro(){
String urlx="https://ja.wikipedia.org/wiki/%E6%B8%85%E5%8E%9F%E5%92%8C%E5%8D%9A";
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;
}
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;
writexml("ren.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月14日 14:14