アットウィキロゴ

bfds

import java.io.*;

class data{

String urlx,bun;
String[] data=new String[5000];
String[] link=new String[5000];
String[] credit=new String[5000];


String[] point2=new String[5000];
String[] author2=new String[5000];
String[] content2=new String[5000];
String[] title2=new String[5000];

int[] x=new int[5000];
int[] y=new int[5000];
int s,datanumber,xmlnumber;
int p1,p2,s1,s2,j;
String rv,str,point,author,title;
int n;

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

data(){

readfile("link.txt");

for(n=1;n<101;n++){

link[1]=data[n];

urlx=link[1];

getdata gt=new getdata();
gt.makedata(urlx);
bun=gt.data;

p1=bun.indexOf("<p>");
p2=bun.indexOf("</p>",p1);

rv=bun.substring(p1+3,p2);

rv=rv.replace("<br />","");

content2[n]=rv;

xymaker(bun);

for(s=1;s<xmlnumber;s++){
str=bun.substring(x[s],y[s]);
if(str.indexOf("点")>1)point=str;
}

p1=point.indexOf("alt");
p2=point.indexOf("点",p1);

point=point.substring(p1+5,p2);

point2[n]=point;

p1=bun.indexOf("commonPostInfo");
p2=bun.indexOf("f_delbbs",p1);

author=bun.substring(p1,p2);

j=0;
if(author.indexOf("未登録")>0)j=100;
if(j<50)makeauthor();
if(j>50)nonau();

author2[n]=author;

for(s=1;s<50;s++){
str=bun.substring(x[s],y[s]);
if(str.equals("<title"))s1=s;
if(str.equals("</title"))s2=s;
}

title=bun.substring(y[s1],x[s2]);

p1=title.indexOf("」");
p2=title.indexOf("@");

title=title.substring(p1+1,p2);

title2[n]=title;

}

writefile();



}
void nonau(){
int p1,p2;

p1=author.indexOf("未登録");
p1=author.indexOf(">",p1);
p2=author.indexOf("<",p1);
author=author.substring(p1+1,p2);
}

void makeauthor(){

String[] z=author.split(">");
for(s=1;s<z.length;s++){
if(z[s].indexOf("</a")>0)author=z[s];
}

author=author.replace("</a","");
}

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 writefile(){

try{
PrintWriter pw = new PrintWriter
(new BufferedWriter(new FileWriter("xml.txt")));

for(n=1;n<10;n++){                                                                                                                                                                              
pw.print("<data>");                                                                
pw.print("<title>");                                                                
pw.print(title2[n]);                                                                
pw.print("</title>");  
pw.print("<author>");                                                                
pw.print(author2[n]);                                                                
pw.print("</author>");
pw.print("<content>");                                                                
pw.print(content2[n]);                                                                
pw.print("</content>");
pw.print("<point>");                                                                
pw.print(point2[n]);                                                                
pw.print("</point>");
pw.println("</data>");                                                                
}

System.out.println("ファイルに書きこみました。");
pw.close();
}
catch(IOException ep){ System.out.println("入出力エラーです。"); }

}



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年06月30日 13:13