アットウィキロゴ

かんぱく

package pig;
import tool.*;
 
public class pro {
 
    int s,datanumber;
String[] data=new String[500000];
    String[] namex=new String[5000];
    String[] link=new String[9000];
 String id,title;
 
    public static void main(String[] args) {
        pro t=new pro();
    }
 
    pro(){
 
          String urlx="http://www.e-stat.go.jp/SG1/estat/List.do?bid=000001024923&cycode=0";
 
 
 
  getd sub2=new getd();
   sub2.makedata(urlx,"UTF-8");
   data=sub2.data;
   datanumber=sub2.datanumber;
 
   int sx=0;
   String str="";
for(s=1;s<datanumber+1;s++){   
     str=str+data[s];
 
 
    } 
 
String[] x=str.split("</tr>");        
 
sx=0;
for(s=0;s<x.length;s++){
x[s]=x[s].replace(" ","");
x[s]=x[s].replace("	","");	
if(x[s].indexOf("./Xlsdl")>-1)sx=sx+1;
if(x[s].indexOf("./Xlsdl")>-1)link[sx]=x[s];
};
 
int number=sx;
 
 
for(s=1;s<number+1;s++){
 int p1=link[s].indexOf("/Xlsdl");
 int p2=link[s].indexOf("\"",p1);
 link[s]="http://www.e-stat.go.jp/SG1/estat/"+link[s].substring(p1,p2);
 System.out.println(link[s]);
    }
 
 
for(s=1;s<number+1;s++){
 dl dlx=new dl();
 dlx.makedata(link[s],"data/"+s+".xls");
    }
 
 
 
 
 
 
 
    }
 
 
 
 
}
 
 
package pig;
 
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.URL;
import java.net.HttpURLConnection;
 
public class getd {
 
    int s,datanumber;
    String[] data=new String[500000];
 
    void makedata(String urlx,String code){
 
 
 
        try {
 
 
 
            URL connectUrl = new URL(urlx);
 
            HttpURLConnection con = (HttpURLConnection)connectUrl .openConnection();
            con.setRequestMethod("GET");
 
            con.connect();
 
            BufferedReader reader = new BufferedReader(new InputStreamReader(con.getInputStream(), code));
 
            s=0;
            String line;
            StringBuilder sb = new StringBuilder();
            while ((line = reader.readLine()) != null) {
                s=s+1;
                data[s]=line;
            }
 
            datanumber=s;
 
            reader.close();
            con.disconnect();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
 
 
 
package pig;
 
import java.io.*;
import java.net.*;
 
public class dl {
 
    String urlx;
   String[] data=new String[5000];
   int s,datanumber; 
 
 
 
 
 
 
 
  void makedata(String urlx,String file){  
 
 
 
  try{ 
        URL url = new URL(urlx); 
 
        InputStream in = url.openStream();  
        OutputStream out = new FileOutputStream(file);
 
try {  
            byte[] buf = new byte[1024];  
            int len = 0;  
 
            while ((len = in.read(buf)) > 0){   
                out.write(buf, 0, len);  
            }  
 
            out.flush();  
        } finally {  out.close();  in.close();  }  
 
 
} catch(Exception e) { System.err.println(e); }   
 
 
 
  }
 
}
 
最終更新:2016年07月14日 08:35