package goo;
import tool.*;
import java.io.*;
public class pro {
int s,datanumber;
String[] data=new String[5000];
int number;
String[] namex=new String[500];
String[] timex=new String[500];
String[] link=new String[500];
String[] web=new String[500];
int number_goo;
public static void main(String[] args) {
pro r=new pro();
}
pro(){
readfile sub2=new readfile();
sub2.makedata("goo.csv","UTF-8");
web=sub2.data;
number_goo=sub2.datanumber;
int tr;
for(tr=2;tr<number_goo+1;tr++){
String urlx=web[tr];
String ff=urlx.replace("https://tvtopic.goo.ne.jp/program/", "");
ff=ff.replace("/", "");
System.out.println(ff);
getdata sub=new getdata();
sub.makedata(urlx,"UTF-8");
data=sub.data;
datanumber=sub.datanumber;
String pp="<span class=\"min\">";
String[] cr=new String[500];
int sx=0;
for(s=1;s<datanumber+1;s++){
int h=0;
if(data[s].indexOf("/program/")>-1)h=h+1;
if(data[s].indexOf(pp)>-1)h=h+1;
if(h==2)sx=sx+1;
if(h==2)cr[sx]=data[s];
}
number=sx;
for(s=1;s<number+1;s++){
int p1=cr[s].indexOf("</span>");
int p2=cr[s].indexOf("</a>",p1);
namex[s]=cr[s].substring(p1,p2);
p1=cr[s].indexOf("/program/");
p2=cr[s].indexOf("\"",p1);
link[s]="https://tvtopic.goo.ne.jp"+cr[s].substring(p1,p2);
p1=cr[s].indexOf(pp);
p2=cr[s].indexOf("</span>",p1);
timex[s]=cr[s].substring(p1,p2);
timex[s]=clean_str(timex[s]);
namex[s]=clean_str(namex[s]);
}
writexml("data/"+ff+".txt");
}
}
void writexml(String file){
int s,sx;
try{
PrintWriter pw = new PrintWriter (new BufferedWriter(new FileWriter(file)));
for(s=1;s<number+1;s++){
pw.println(timex[s]+","+namex[s]+","+link[s]);
}
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年05月02日 13:15