zoukankan      html  css  js  c++  java
  • 简单的爬虫实现


    //1、创建一个测试类,取名为TestHttpClient public class TestHttpClient{ //2、创建获取数据的方法get public void get() { //3、创建http对象 CloseableHttpClient httpClient = HttpClients.createDefault(); //4、模拟get请求(这里地址取的是新浪上的一篇博文) String url = "http://blog.sina.com.cn/s/blog_149f87a9e0102x3i8.html"; HttpGet get = new HttpGet(url); //5、创建一个返回对象 CloseableHttpResponse response = HttpClient.execute(get); //6、通过工具类转换成一个字符串,字符串就是网页的内容 String html = EntityUtils.toString(response.getEntity()
    ,“utf-8”
    ); //7、将获取的内容打印出来 system.out.print(html); } }

      Entity代表网页的实体内容

  • 相关阅读:
    Nmap笔记
    Spring AOP(一)
    Spring IOC(三)
    Spring IOC(二)
    Spring IOC(一)
    bootstrap 使用(三)
    bootstrap 使用(二)
    bootstrap 使用(一)
    js(二)
    QQ邮件
  • 原文地址:https://www.cnblogs.com/sxpy-lj/p/7323979.html
Copyright © 2011-2022 走看看