import java.io.*;
class ren{
String[] data=new String[50000];
String[] link=new String[50000];
String[] credit=new String[500];
String[] page=new String[500000];
String[] don=new String[500000];
int[] x=new int[5000];
int[] y=new int[5000];
int s,sx,datanumber,xmlnumber;
String bun,urlx,str,url;
int h,creditnumber;
int p1,p2;
String str1,str2;
int p,pn,pagenumber;
public static void main(String [] args) {
ren test=new ren();
}
ren(){
readfile("ren.txt");
for(s=1;s<datanumber+1;s++){
link[s]=data[s];
}
pn=0;
for(p=1;p<datanumber+1;p++){
urlx=link[p];
getdata g=new getdata();
g.makedata(urlx);
bun=g.data;
xymaker(bun);
sx=0;
for(s=1;s<xmlnumber+1;s++){
str=creditmaker(s,bun);
h=0;
if(str.indexOf("href")>1)h=h+1;
if(str.indexOf("TARGET")>1)h=h+1;
if(h==2)sx=sx+1;
if(h==2)credit[sx]=str;
}
creditnumber=sx;
for(s=1;s<creditnumber+1;s++){
p1=credit[s].indexOf("/");
p2=credit[s].indexOf("a.html");
str1=credit[s].substring(p1,p2);
p1=urlx.indexOf("/main");
str2=urlx.substring(0,p1);
url=str2+str1;
url=url+"c.";
url=url+"html";
pn=pn+1;
don[pn]=url;
}
System.out.println(pn);
}
pagenumber=pn/2;
for(s=1;s<pagenumber+1;s++){
sx=2*s;
page[s]=don[sx];
}
writefile();
}
void writefile(){
try{
PrintWriter pw = new PrintWriter
(new BufferedWriter(new FileWriter("page.txt")));
for(s=1;s<pagenumber+1;s++){
pw.println(page[s]);
}
System.out.println("ファイルに書きこみました。");
pw.close();
}
catch(IOException ep){ System.out.println("入出力エラーです。"); }
}
String creditmaker(int s,String str){
int p1,p2;
String bara;
p1=x[s];
p2=y[s];
bara=str.substring(p1+1,p2);
return bara;
}
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年06月26日 12:04