0

I am coding a website scrapping for my research project. During regular website browsing I submit the form, and have data presented. There are links to next pages with more data. There is also link to download data for the data presented in Excel file.

I am using Jsoup to login and to parse the website. How can I submit and download data in Excel files using Jsoup or any other parser or method?

This is the header which I am getting when clicking on download link:

http://www.xxx.xx/iss/modules/doSave2XLS_sel.asp

POST /iss/modules/doSave2XLS_sel.asp HTTP/1.1
Host: www.skrin.ru
User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:14.0) Gecko/20100101 Firefox/14.0.1
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language: en-us,en;q=0.5
Accept-Encoding: gzip, deflate
Connection: keep-alive
Referer: http://www.xxx.xxx/dbsearch/dbsearchru/companies/
Cookie: ssid=1001797; ASPSESSIONIDQSBATRTS=GLKHPLMDGMBMNBDFDJNK; have_cookies=1; 1stopen=1; b=b; bask%5Fid=708D9FFEF85146BC9C50AA2B101F153D; storedID=217311703191792; user%5Flogin=CGUTST; sessionid=1063501797; ASPSESSIONIDSQAATQSS=LDGPAKNDAEOOHEJPAPCNCKHN; ASPSESSIONIDQQDCTRSS=MACDCINHAFEJMLJCCO; ASPSESSIONIDQSACSRSS=FEOLDGPDIJIICGD
Content-Type: application/x-www-form-urlencoded
Content-Length: 1251
uid=1886&iss=%27on%27%2C%27AABAAD075E04C325674A0039F724%27%2C%273DC84DD11C51C32567400032199E%27%2C%27FB9900A46791499BA08BC3\CFA39%27%2C%27E21096B5CCABA8424325685700350F60%27%2C%2795345C101FAE47979E25CBF409044F11%27%2C%2791001D2C33036B8C43256735005A6F38%27%2C%27A407F1FA59BB4243A2321D1D561D05FC%27%2C%27038D4548E9E3448DA85C397BB8E7813C%27%2C%2743256B410056E49F43256B6600535ADB%27%2C%277A3678AD5AE14B0A945D0EB6B7919F6E%27%2C%273E7F2B1C9DF045C2B490D064C27012E0%27%2C%2709D6465D27A13F4443256918005508F6%27%2C%27432569290063957443256A3C002D1886%27%2C%2706303D64278B47F143256735005AB499%27%2C%2799F954C23CAB4D5884AC647F1D03A991%27%2C%273A4856543CEF4C7BA37F4CFBA837EA23%27%2C%27612B5284D9604368B86A3CFF7BF84916%27%2C%2714C8FC8A807C494C29F5DA20%27%2C%27B44C85F39BA64922BAC5E665DD9D968C%27%2C%27A4519C3DC0CB4F8E83EA3CBCB19DC60C%27%2C%2741DDBC39B3584C5CB81ABF9B3EFA91E5%27%2C%27D3068AD3F90441E7B8ABCCE5ADD12D07%27%2C%277E75E0F682AD84B4C3256763002EA999%27%2C%27A1DAA1A271404F049AB543DC7FD14CC5%27%2C%27A43E335F235F4F5CA087B2B1B42304BC%27%2C%275E7E15B019C84AA188BFB03B5C416639%27%2C%27F695456883C04C91B47D204576FA6033%27%2C%27E765622FA33F4B13AAC56348E62C69C5%27%2C%2741113AD02A6A43F9A6A6F20D0CDEA7F1%27%2C%270F36F00CC10F4E60B9226BCE04EA462B%27

HTTP/1.1 200 OK
Date: Wed, 12 Dec 2012 02:48:16 GMT
Server: Microsoft-IIS/6.0
X-Powered-By: ASP.NET
Content-Disposition: attachment; filename=188664846.xls;
Content-Length: 33491
Content-Type: application/vnd.ms-excel
Expires: Wed, 12 Dec 2012 02:48:16 GMT
Set-Cookie: ssid=1063501797; expires=Mon, 14-Jan-2013 20:00:00 GMT; path=/
Cache-Control: private

This is how page looks like:

data

4

1 に答える 1

1

java.net.URLConnection を使用して投稿データを送信します。

サーバーの応答はエクセルのデータです。ローカルファイルを保存...

例えば:

       try{   
             String postData = "uid=1886&iss=%27on%27%2C%27AABAAD075E04C325674A0039F724%27%2C%273DC84DD11C51C32567400032199E%27%2C%27FB9900A46791499BA08BC3\CFA39%27%2C%27E21096B5CCABA8424325685700350F60%27%2C%2795345C101FAE47979E25CBF409044F11%27%2C%2791001D2C33036B8C43256735005A6F38%27%2C%27A407F1FA59BB4243A2321D1D561D05FC%27%2C%27038D4548E9E3448DA85C397BB8E7813C%27%2C%2743256B410056E49F43256B6600535ADB%27%2C%277A3678AD5AE14B0A945D0EB6B7919F6E%27%2C%273E7F2B1C9DF045C2B490D064C27012E0%27%2C%2709D6465D27A13F4443256918005508F6%27%2C%27432569290063957443256A3C002D1886%27%2C%2706303D64278B47F143256735005AB499%27%2C%2799F954C23CAB4D5884AC647F1D03A991%27%2C%273A4856543CEF4C7BA37F4CFBA837EA23%27%2C%27612B5284D9604368B86A3CFF7BF84916%27%2C%2714C8FC8A807C494C29F5DA20%27%2C%27B44C85F39BA64922BAC5E665DD9D968C%27%2C%27A4519C3DC0CB4F8E83EA3CBCB19DC60C%27%2C%2741DDBC39B3584C5CB81ABF9B3EFA91E5%27%2C%27D3068AD3F90441E7B8ABCCE5ADD12D07%27%2C%277E75E0F682AD84B4C3256763002EA999%27%2C%27A1DAA1A271404F049AB543DC7FD14CC5%27%2C%27A43E335F235F4F5CA087B2B1B42304BC%27%2C%275E7E15B019C84AA188BFB03B5C416639%27%2C%27F695456883C04C91B47D204576FA6033%27%2C%27E765622FA33F4B13AAC56348E62C69C5%27%2C%2741113AD02A6A43F9A6A6F20D0CDEA7F1%27%2C%270F36F00CC10F4E60B9226BCE04EA462B%27";
             URL url = new URL("http://www.xxx.xx/iss/modules/doSave2XLS_sel.asp");   
             conn = (HttpURLConnection)url.openConnection();   
             conn.setDoOutput(true);   
             conn.setRequestMethod("POST");   
             conn.setUseCaches(false);   
             conn.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");   
             conn.setRequestProperty("Content-Length", String.valueOf(postData.length()));   
             conn.setRequestProperty("Cookie","ssid=1001797; ASPSESSIONIDQSBATRTS=GLKHPLMDGMBMNBDFDJNK; have_cookies=1; 1stopen=1; b=b; bask%5Fid=708D9FFEF85146BC9C50AA2B101F153D; storedID=217311703191792; user%5Flogin=CGUTST; sessionid=1063501797; ASPSESSIONIDSQAATQSS=LDGPAKNDAEOOHEJPAPCNCKHN; ASPSESSIONIDQQDCTRSS=MACDCINHAFEJMLJCCO; ASPSESSIONIDQSACSRSS=FEOLDGPDIJIICGD");
             conn.setDoInput(true);   
             conn.connect();   

             OutputStreamWriter out = new OutputStreamWriter(conn.getOutputStream(), "UTF-8");   
             out.write(postData);   
             out.flush();   
             out.close();   
          InputStream in = conn.getInputStream();
          //TODO read the in and to save local file...


   }catch(Exception ex){
      //TODO
   }
于 2012-12-12T03:52:04.213 に答える