package vgx;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileInputStream;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
public class pro {
String[] data=new String[500000];
int s,datanumber;
String[] v=new String[500000];
String[] t=new String[500000];
String title,sta,term,time;
String[] art=new String[500000];
String[] m=new String[500000];
String[] d=new String[500000];
int number;
public static void main(String[] args) {
pro t=new pro();
}
pro(){
String str1="<h2>キャスト</h2>";
String str2="<h2>スタッフ</h2>";
int tr;
for(tr=1;tr<848;tr++){
readx("data/"+tr+".txt");
title="";
int s1=0;
int s2=0;
int s3=0;
for(s=2;s<datanumber+1;s++){
if(data[s].indexOf(str1)>-1)s1=s;
if(data[s].indexOf(str2)>-1)s2=s;
if(data[s].indexOf("detail-text-area")>-1)s3=s;
if(data[s].indexOf("<title>")>-1)title=data[s];
}
String str="";
for(s=s3+1;s<s1;s++){
str=str+data[s];
}
String[] x1=str.split("</tr>");
sta="";
term="";
time="";
int sx=0;
for(s=0;s<x1.length;s++){
String[] y1=x1[s].split("</td>");
String k1=change(y1[0]);
String de="";
if(y1.length>2)de=y1[2];
if(k1.indexOf("放送局")>-1)sta=change(de);
if(k1.indexOf("クール")>-1)term=change(de);
if(k1.indexOf("時間帯")>-1)time=change(de);
}
title=change(title);
System.out.println(tr+","+title);
str="";
for(s=s1+1;s<s2;s++){
str=str+data[s];
}
String[] x=str.split("</tr>");
sx=0;
for(s=0;s<x.length;s++){
String[] y=x[s].split("</td>");
if(y.length>1)sx=sx+1;
if(y.length>1)art[sx]=change(y[1]);
}
for(s=1;s<sx+1;s++){
art[s]=art[s].replace(" ","");
}
number=sx;
writexml("gdata/"+tr+".txt");
}
}
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;
}
void writexml(String file){
int s,sx;
try{
PrintWriter pw = new PrintWriter (new BufferedWriter(new FileWriter(file)));
pw.println(title);
pw.println(sta);
pw.println(term);
pw.println(time);
for(s=1;s<number+1;s++){
pw.println(art[s]);
}
System.out.println("ファイルに書きこみました。");
pw.close();
} catch(IOException ep){ System.out.println("入出力エラーです。"); }
}
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;
}
int numx(String str){
int nx;
nx=0;
try{
nx=Integer.parseInt(str);
}catch (Exception e) {}
return nx;
}
}
最終更新:2016年07月31日 01:37