杭州搖號網站分頁顯示,瀏覽起來很是的不方便,因而寫了幾行代碼java
將它給所有下載到一個文件中。代碼很簡單,先經過httpwatch觀察,httpapp
是如何拼接請求的,而後在代碼中將連接拼接好,批量下載下來。工具
PrintStream ps = null; try { ps = new PrintStream(new FileOutputStream("company.txt")); } catch (FileNotFoundException e1) { e1.printStackTrace(); } for(int i = 1; i <= 40; i++){ HttpClient client = new DefaultHttpClient(); //http://apply.hzcb.gov.cn/apply/app/status/norm/unit //http://apply.hzcb.gov.cn/apply/app/status/norm/person HttpPost httppost = new HttpPost("http://apply.hzcb.gov.cn/apply/app/status/norm/unit"); httppost.setHeader("Referer","http://apply.hzcb.gov.cn/apply/app/status/norm/unit"); List<NameValuePair> params = new ArrayList<NameValuePair>(); String pageNo = new Integer(i).toString(); params.add(new BasicNameValuePair("pageNo", pageNo)); params.add(new BasicNameValuePair("issueNumber", "201405")); params.add(new BasicNameValuePair("applyCode", "")); httppost.setEntity(new UrlEncodedFormEntity(params)); HttpResponse response = client.execute(httppost); HttpEntity entity = response.getEntity(); // 在這裏能夠用Jsoup之類的工具對返回結果進行分析,以判斷登陸是否成功 String postResult = EntityUtils.toString(entity, "GBK"); Document document = Jsoup.parse(postResult); Elements carpersons = document.select("tr.content_data"); for(Element e : carpersons){ String id = ""; String name = ""; Elements props = e.select("td"); int count = 0; for(Element e1 : props){ if(count == 0) id = e1.text(); else name = e1.text(); count++; } System.out.println("id:" + id + " name:" + name); ps.println(id + "\t" + name); } } if (null != ps) { ps.close(); } }