アットウィキロゴ

memo88

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import tool.*; 
import java.io.File;
import java.io.FileWriter;
import java.io.PrintWriter;
 
public class pro {
 
     int s,datanumber;
    String[] data=new String[5000];
     String[] link=new String[5000];
 
        String[] title=new String[5000];
        String[] date=new String[5000];
        String[] actor=new String[5000];
         String[] subtitle=new String[5000];
 
             String[] subdata=new String[500000];
 
    public static void main(String[] args) {
        pro te=new pro();
    }
 
    pro(){
 
        File d=new File("data");
        String[] dd=d.list();
 
        int tx=0;
        int tr;
        for(tr=0;tr<dd.length;tr++){
 
           readx("data/"+dd[tr]);
 
        String str="";
 
        for(s=1;s<datanumber+1;s++){
        if(data[s].indexOf("programlist")>-1)str=data[s];
 
        }
 
 
 
            String[] x=str.split("</tr>");
 
            int sx;
     for(s=0;s<x.length;s++){       
     x[s]=x[s].replace("</th>","</td>");
     link[s+1]="";
     String[] y=x[s].split("</td>");
     for(sx=0;sx<y.length;sx++){
      y[sx]=change(y[sx]);
     if(sx==1)link[s+1]=y[sx];
     }
     }
 
     int number=x.length;
 
     for(s=1;s<number+1;s++){
 
     String[] x1=link[s].split("△");
     title[s]="";
     date[s]="";
     actor[s]="";
     for(sx=1;sx<x1.length;sx++){ 
     if(sx==1)title[s]=x1[sx];
     if(sx==2)date[s]=x1[sx];
     if(sx==3)actor[s]=x1[sx];
     }
 
     }      
 
    for(s=1;s<number+1;s++){   
    int p1=date[s].indexOf("』");
    subtitle[s]="";
   if(p1>-1)subtitle[s]=date[s].substring(0,p1+1);
    if(p1>-1)date[s]=date[s].substring(p1+1,date[s].length());
    date[s]=date[s].replace("』", "");  
    }
 
 
    for(s=1;s<number+1;s++){
    if(title[s].length()>0)tx=tx+1;
    if(title[s].length()>0)subdata[tx]=date[s]+","+title[s]+","+subtitle[s]+","+actor[s];
    }
 
 
        }    
 
        datanumber=tx;
 
        writexml("tv.csv");
 
 
    }
 
 
       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<11;n++){
        str=rev(str);    
        }
 
        str=str.replace("△△","△");
      str=str.replace("△△","△");
     str=str.replace("△△","△");
      str=str.replace("&nbsp;","");
        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);
        if(p2>-1)str=str.replace(strx,"△");
 
        return str;
    }    
 
 
     void readx(String file){
 
String str;
BufferedReader br;  
int s;
s=0;
try {
br = new BufferedReader(new InputStreamReader(new FileInputStream(file),"UTF-8"));  
while((str = br.readLine()) != null) {  
s=s+1;
data[s]=str;  
}
br.close();
} catch (IOException e) {System.out.println(e);}  
 
datanumber=s;
 
} 
 
}
 
最終更新:2016年07月29日 23:44