欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

SpringBoot中使用Jsoup爬取網(wǎng)站數(shù)據(jù)的方法

 更新時間:2020年06月08日 15:10:07   作者:劉桐ssss  
這篇文章主要介紹了SpringBoot中使用Jsoup爬取網(wǎng)站數(shù)據(jù)的方法,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧

爬取數(shù)據(jù)

導(dǎo)入jar包

 <properties>
    <java.version>1.8</java.version>
    <elasticsearch.version>7.6.1</elasticsearch.version>
  </properties>
 
  <dependencies>
    <dependency>
      <groupId>org.jsoup</groupId>
      <artifactId>jsoup</artifactId>
      <version>1.10.2</version>
    </dependency>
    <dependency>
      <groupId>com.alibaba</groupId>
      <artifactId>fastjson</artifactId>
      <version>1.2.62</version>
    </dependency>
    <dependency>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-starter-data-redis</artifactId>
    </dependency>
    <dependency>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-starter-data-elasticsearch</artifactId>
    </dependency>
    <dependency>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-starter-thymeleaf</artifactId>
    </dependency>
    <dependency>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-starter-web</artifactId>
    </dependency>
 
    <dependency>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-devtools</artifactId>
      <scope>runtime</scope>
      <optional>true</optional>
    </dependency>
    <dependency>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-configuration-processor</artifactId>
      <optional>true</optional>
    </dependency>
    <dependency>
      <groupId>org.projectlombok</groupId>
      <artifactId>lombok</artifactId>
      <optional>true</optional>
    </dependency>
    <dependency>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-starter-test</artifactId>
      <scope>test</scope>
      <exclusions>
        <exclusion>
          <groupId>org.junit.vintage</groupId>
          <artifactId>junit-vintage-engine</artifactId>
        </exclusion>
      </exclusions>
    </dependency>
  </dependencies>

新建實體類

@Data
@NoArgsConstructor
@AllArgsConstructor
public class Content {
  private String title;
  private String img;
  private String price;
}

編寫爬蟲工具類

public class HtmlParseUtil {
  public static void main(String[] args) throws Exception {
    new HtmlParseUtil().parseDDJJ("包").forEach(System.out::println);
  }
 
  public List<Content> parseDDJJ(String keywords) throws Exception {
    //爬取url地址
    String url = "https://search.xxxx.com/Search?keyword="+keywords;
    //解析網(wǎng)頁,30s內(nèi)未爬取成功,打印錯誤
    Document document = Jsoup.parse(new URL(url),30000);
    //獲取每一本書籍的id
    Element element = document.getElementById("DJ_goodsList");
    //獲取所有的li標簽
    Elements elements = element.getElementsByTag("li");
 
    ArrayList<Content> goodsList = new ArrayList<>();
 
    //遍歷li標簽的內(nèi)容
    for (Element el : elements) {
      String img = el.getElementsByTag("img").eq(0).attr("src");
      String price = el.getElementsByClass("p-price").eq(0).text();
      String title = el.getElementsByClass("p-name").eq(0).text();
 
      Content content = new Content();
      content.setTitle(title);
      content.setPrice(price);
      content.setImg(img);
      goodsList.add(content);
    }
    return goodsList;
  }
}

可以看到內(nèi)容、圖片、價格系數(shù)爬取

到此這篇關(guān)于SpringBoot中使用Jsoup爬取網(wǎng)站數(shù)據(jù)的方法的文章就介紹到這了,更多相關(guān)SpringBoot Jsoup爬取內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

  • spring security中Authority、Role的區(qū)別及說明

    spring security中Authority、Role的區(qū)別及說明

    這篇文章主要介紹了spring security中Authority、Role的區(qū)別及說明,具有很好的參考價值,希望對大家有所幫助,如有錯誤或未考慮完全的地方,望不吝賜教
    2023-09-09
  • Java集合基礎(chǔ)知識 List/Set/Map詳解

    Java集合基礎(chǔ)知識 List/Set/Map詳解

    這篇文章主要介紹了Java集合基礎(chǔ)知識 List/Set/Map,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧
    2019-03-03
  • java字節(jié)字符轉(zhuǎn)換流操作詳解

    java字節(jié)字符轉(zhuǎn)換流操作詳解

    這篇文章主要介紹了java字節(jié)字符轉(zhuǎn)換流操作,結(jié)合實例形式詳細分析了Java字符流轉(zhuǎn)換相關(guān)原理、實現(xiàn)方法及操作注意事項,需要的朋友可以參考下
    2019-09-09
  • spring-mvc/springboot使用MockMvc對controller進行測試

    spring-mvc/springboot使用MockMvc對controller進行測試

    這篇文章主要介紹了spring-mvc/springboot使用MockMvc對controller進行測試,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧
    2018-11-11
  • 一文搞懂String的intern()方法

    一文搞懂String的intern()方法

    這篇文章主要給大家介紹String的intern()方法,文中有詳細的代碼示例,感興趣的小伙伴讓我們一起來看看這究竟是個什么玩意
    2023-06-06
  • java設(shè)計模式—靜態(tài)代理模式(聚合與繼承方式對比)

    java設(shè)計模式—靜態(tài)代理模式(聚合與繼承方式對比)

    下面小編就為大家?guī)硪黄猨ava設(shè)計模式—靜態(tài)代理模式(聚合與繼承方式對比)。小編覺得挺不錯的,現(xiàn)在就分享給大家,也給大家做個參考。一起跟隨小編過來看看吧
    2017-05-05
  • 詳解J2EE開發(fā)的網(wǎng)站部署到阿里云服務(wù)器的方法

    詳解J2EE開發(fā)的網(wǎng)站部署到阿里云服務(wù)器的方法

    這篇文章主要介紹了詳解J2EE開發(fā)的網(wǎng)站部署到阿里云服務(wù)器的方法,需要的朋友可以參考下
    2018-01-01
  • SpringMVC基于配置的異常處理器

    SpringMVC基于配置的異常處理器

    這篇文章主要為大家介紹了SpringMVC基于配置的異常處理器,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進步,早日升職加薪
    2022-05-05
  • Mybatis-plus全局id生成策略詳解

    Mybatis-plus全局id生成策略詳解

    這篇文章主要介紹了Mybatis-plus全局id生成策略詳解,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教
    2022-01-01
  • SpringBoot3集成WebSocket的全過程

    SpringBoot3集成WebSocket的全過程

    WebSocket通過一個TCP連接在客戶端和服務(wù)器之間建立一個全雙工、雙向的通信通道,使得客戶端和服務(wù)器之間的數(shù)據(jù)交換變得更加簡單,本文給大家介紹了SpringBoot3集成WebSocket的全過程,并有相關(guān)的代碼示例供大家參考,需要的朋友可以參考下
    2024-05-05

最新評論