アットウィキロゴ

記事の分析

import java.io.*;

class ren{

String[] data=new String[1004];  
String[] article=new String[1004];  
int[] x=new int[100];
int[] y=new int[100];
int xmlnumber;
int datanumber,s,sx,p1,p2;
String bun,str,file;
int page;


public static void main(String [] args) {
        ren test=new ren();
            }

ren(){

for(page=1;page<23;page++){

file="data/";
file=file+page;
file=file+".txt";

readfile(file);

for(s=1;s<datanumber+1;s++){
article[s]=data[s];
}

for(s=1;s<datanumber+1;s++){

bun=article[s];
p1=bun.indexOf("<a href=");
p2=bun.indexOf("</a");
while(p1>-1){
p1=bun.indexOf("<a href=");
p2=bun.indexOf("</a");
if(p1>-1)str=bun.substring(0,p1);
if(p1>-1)bun=str+bun.substring(p2+4,bun.length());
}
bun=bun.replace("<br/>","");
bun=bun.replace("<br />","");
bun=bun.replace("</dd>","");
article[s]=bun;
}

for(s=1;s<datanumber+1;s++){
bun=article[s];
p1=bun.indexOf("スポンサードリンク");
if(p1>0)bun=bun.substring(0,p1);
p1=bun.indexOf("<span");
if(p1>0)bun=bun.substring(0,p1);
article[s]=bun;
}

System.out.println(article[1]);

file="gdata/";
file=file+page;
file=file+".txt";

writefile(file);

}

}

void writefile(String file){

try{
PrintWriter pw = new PrintWriter (new BufferedWriter(new FileWriter(file)));

for(s=1;s<datanumber;s++){
pw.println(article[s]);
}
  
System.out.println("ファイルに書きこみました。");
pw.close();
} catch(IOException ep){ System.out.println("入出力エラーです。"); }


}

void xymaker(String str){
int p1;
int s;
s=1;
p1=str.indexOf("<");
x[1]=p1;
while(p1>-1){
p1=str.indexOf("<",p1+1);
if(p1>-1)s=s+1;
if(p1>-1)x[s]=p1;
}
xmlnumber=s;
for(s=1;s<xmlnumber+1;s++){
y[s]=str.indexOf(">",x[s]);
}

}

void readfile(String file){

String str;
BufferedReader br;  

s=0;
try {
br = new BufferedReader(new InputStreamReader(new FileInputStream(file),"SJIS"));  
while((str = br.readLine()) != null) {  
s=s+1;
data[s]=str;  
}
br.close();
} catch (IOException e) {System.out.println(e);}  

datanumber=s;

}



}
最終更新:2011年07月12日 03:08