package tv8;
import tool.*;
import java.io.*;
public class pro {
int s,datanumber;
String[] data=new String[5000];
String[] credit=new String[5000];
String[] link=new String[5000];
int number;
public static void main(String[] args) {
pro t=new pro();
}
pro(){
String urlx="https://ja.wikipedia.org/wiki/日本のバラエティ番組一覧";
getdata sub2=new getdata();
sub2.makedata(urlx,"UTF-8");
data=sub2.data;
datanumber=sub2.datanumber;
int sx=0;
for(s=1;s<datanumber+1;s++){
int h=0;
if(data[s].indexOf("<li>")>-1)h=h+1;
if(data[s].indexOf("/wiki")>-1)h=h+1;
if(data[s].indexOf("index.php?")>-1)h=100;
if(h==2)sx=sx+1;
if(h==2)link[sx]=data[s];
}
number=sx;
for(s=1;s<number+1;s++){
int p1=link[s].indexOf("/wiki/");
int p2=link[s].indexOf("\"",p1);
link[s]="https://ja.wikipedia.org"+link[s].substring(p1,p2);
System.out.println(link[s]);
}
int tr;
for(tr=1;tr<number+1;tr++){
urlx=link[tr];
wiki sub5=new wiki();
sub5.makedata(urlx, "data/"+tr+".txt");
}
}
}
package tv8;
import tool.*;
import java.io.*;
public class wiki {
int s,datanumber;
String[] data=new String[5000];
String[] credit=new String[5000];
String[] name=new String[5000];
int number;
void makedata(String urlx,String file){
getdata sub2=new getdata();
sub2.makedata(urlx,"UTF-8");
data=sub2.data;
datanumber=sub2.datanumber;
int s1=0;
for(s=1;s<datanumber+1;s++){
if(data[s].indexOf("infobox")>-1)s1=s;
}
if(s1>10){
int s2=0;
for(s=s1;s<datanumber+1;s++){
int h=0;
if(data[s].indexOf("</table>")>-1)h=h+1;
if(s2==0)h=h+1;
if(h==2)s2=s;
}
String str="";
for(s=s1;s<s2;s++){
str=str+data[s];
}
String[] x=str.split("</tr>");
int sx;
for(s=0;s<x.length;s++){
x[s]=x[s].replace("</th>","△");
x[s]=x[s].replace("</td>","△");
x[s]=x[s].replace("<br />","○");
String[] y=x[s].split("△");
credit[s]="";
name[s]="";
for(sx=0;sx<y.length;sx++){
if(sx==0)credit[s]=change(y[sx]);
if(sx==1)name[s]=change(y[sx]);
}
}
number=x.length;
writexml(file);
}
}
void writexml(String file){
int s,sx;
try{
PrintWriter pw = new PrintWriter (new BufferedWriter(new FileWriter(file)));
for(s=0;s<number;s++){
pw.print("<credit>");
pw.print(credit[s]);
pw.print("</credit>");
pw.print("<value>");
pw.print(name[s]);
pw.println("</value>");
}
System.out.println("ファイルに書きこみました。");
pw.close();
} catch(IOException ep){ System.out.println("入出力エラーです。"); }
}
String change(String str){
int n;
for(n=1;n<21;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年03月21日 18:05