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();

                

            }

        }

    }

2. [图片] QQ截图20141120145242.png    

java爬虫03

转载于:https://my.oschina.net/u/238082/blog/690678

相关文章:

  • 2022-01-01
  • 2021-09-16
猜你喜欢
  • 2022-12-23
  • 2021-12-31
  • 2021-09-30
  • 2022-12-23
  • 2021-10-20
  • 2021-11-23
  • 2022-01-01
相关资源
相似解决方案