| public static void main(String[] args) { Integer count = 20; CloseableHttpClient httpclient = HttpClients.createDefault(); HttpPost post = new HttpPost("http://www.oschina.net/fetch_tweets"); List<NameValuePair> nvps = null; try { for (int i = 1; i <= count; i++) { nvps = new ArrayList<NameValuePair>(); nvps.add(new BasicNameValuePair("p", i+"")); post.setEntity(new UrlEncodedFormEntity(nvps, "utf-8")); CloseableHttpResponse response = httpclient.execute(post); String document = EntityUtils.toString(response.getEntity(),"utf-8"); Document doc = Jsoup.parse(document); Elements elements = doc.select("p[class=txt]"); for (Element element:elements) { System.out.println(element.text()); } } }catch(Exception e){ e.printStackTrace(); } finally { if (post!=null) { try { post.clone(); } catch (CloneNotSupportedException e) { e.printStackTrace(); } } if (httpclient!=null) { try { httpclient.close(); } catch (IOException e) { e.printStackTrace(); } } } } |