Warning: error_log(/data/www/wwwroot/hmttv.cn/caches/error_log.php): failed to open stream: Permission denied in /data/www/wwwroot/hmttv.cn/phpcms/libs/functions/global.func.php on line 537 Warning: error_log(/data/www/wwwroot/hmttv.cn/caches/error_log.php): failed to open stream: Permission denied in /data/www/wwwroot/hmttv.cn/phpcms/libs/functions/global.func.php on line 537 成人综合婷婷国产精品久久免费,日本一道本电影,国产亚洲精品色一区

          整合營銷服務(wù)商

          電腦端+手機端+微信端=數(shù)據(jù)同步管理

          免費咨詢熱線:

          用 Java 拿下 HTML 分分鐘寫個小爬蟲

          文適合有 Java 基礎(chǔ)知識的人群

          本文作者:HelloGitHub-秦人

          HelloGitHub 推出的《講解開源項目》系列,今天給大家?guī)硪豢铋_源 Java 版一款網(wǎng)頁元素解析框架——jsoup,通過程序自動獲取網(wǎng)頁數(shù)據(jù)。

          項目源碼地址:https://github.com/jhy/jsoup

          一、項目介紹

          jsoup 是一款 Java 的 HTML 解析器。可直接解析某個 URL 地址的 HTML 文本內(nèi)容。它提供了一套很省力的 API,可通過 DOM、CSS 以及類似于 jQuery 選擇器的操作方法來取出和操作數(shù)據(jù)。

          jsoup 主要功能:

          1. 從一個 URL、文件或字符串中解析 HTML。
          2. 使用 DOM 或 CSS 選擇器來查找、取出數(shù)據(jù)。
          3. 可操作 HTML 元素、屬性、文本。

          二、使用框架

          2.1 準備工作

          • 掌握 HTML 語法
          • Chrome 瀏覽器調(diào)試技巧
          • 掌握開發(fā)工具 idea 的基本操作

          2.2 學習源碼

          將項目導入 idea 開發(fā)工具,會自動下載 maven 項目需要的依賴。源碼的項目結(jié)構(gòu)如下:

          快速學習源碼是每個程序員必備的技能,我總結(jié)了以下幾點:

          1. 閱讀項目 ReadMe 文件,可以快速知道項目是做什么的。
          2. 概覽項目 pom.xml 文件,了解項目引用了哪些依賴。
          3. 查看項目結(jié)構(gòu)、源碼目錄、測試用例目錄,好的項目結(jié)構(gòu)清晰,層次明確。
          4. 運行測試用例,快速體驗項目。

          2.3 下載項目

          git clone https://github.com/jhy/jsoup
          

          2.4 運行項目測試代碼

          通過上面的方法,我們很快可知 example 目錄是測試代碼,那我們直接來運行。注:有些測試代碼需要稍微改造一下才可以運行。

          例如,jsoup 的 Wikipedia 測試代碼:

          public class Wikipedia {
              public static void main(String[] args) throws IOException {
                  Document doc = Jsoup.connect("http://en.wikipedia.org/").get();
                  log(doc.title());
          
                  Elements newsHeadlines = doc.select("#mp-itn b a");
                  for (Element headline : newsHeadlines) {
                      log("%s\n\t%s", headline.attr("title"), headline.absUrl("href"));
                  }
              }
          
              private static void log(String msg, String... vals) {
                  System.out.println(String.format(msg, vals));
              }
          }
          

          說明:上面代碼是獲取頁面(http://en.wikipedia.org/)包含(#mp-itn b a)選擇器的所有元素,并打印這些元素的 title , herf 屬性。維基百科 國內(nèi)無法訪問,所以上面這段代碼運行會報錯。

          改造后可運行的代碼如下:

          public static void main(String[] args) throws IOException {
              Document doc = Jsoup.connect("https://www.baidu.com/").get();
              Elements newsHeadlines = doc.select("a[href]");
              for (Element headline : newsHeadlines) {
                  System.out.println("href: " +headline.absUrl("href") );
              }
          }
          

          三、工作原理

          Jsoup 的工作原理,首先需要指定一個 URL,框架發(fā)送 HTTP 請求,然后獲取響應頁面內(nèi)容,然后通過各種選擇器獲取頁面數(shù)據(jù)。整個工作流程如下圖:

          以上面為例:

          3.1 發(fā)請求

          Document doc = Jsoup.connect("https://www.baidu.com/").get();
          

          這行代碼就是發(fā)送 HTTP 請求,并獲取頁面響應數(shù)據(jù)。

          3.2 數(shù)據(jù)篩選

          Elements newsHeadlines = doc.select("a[href]");
          

          定義選擇器,獲取匹配選擇器的數(shù)據(jù)。

          3.3 數(shù)據(jù)處理

          for (Element headline : newsHeadlines) {
                  System.out.println("href: " +headline.absUrl("href") );
              }
          

          這里對數(shù)據(jù)只做了一個簡單的數(shù)據(jù)打印,當然這些數(shù)據(jù)可寫入文件或數(shù)據(jù)的。

          四、實戰(zhàn)

          獲取豆瓣讀書 -> 新書速遞中每本新書的基本信息。包括:書名、書圖片鏈接、作者、內(nèi)容簡介(詳情頁面)、作者簡介(詳情頁面)、當當網(wǎng)書的價格(詳情頁面),最后將獲取的數(shù)據(jù)保存到 Excel 文件。

          目標鏈接:https://book.douban.com/latest?icn=index-latestbook-all

          4.1 項目 pom.xml 文件

          項目引入 jsoup、lombok、easyexcel 三個庫。

          <?xml version="1.0" encoding="UTF-8"?>
          <project xmlns="http://maven.apache.org/POM/4.0.0"
                   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                   xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
              <modelVersion>4.0.0</modelVersion>
          
              <groupId>org.example</groupId>
              <artifactId>JsoupTest</artifactId>
              <version>1.0-SNAPSHOT</version>
              <properties>
                  <maven.compiler.target>1.8</maven.compiler.target>
                  <maven.compiler.source>1.8</maven.compiler.source>
              </properties>
              <dependencies>
                  <dependency>
                      <groupId>org.jsoup</groupId>
                      <artifactId>jsoup</artifactId>
                      <version>1.13.1</version>
                  </dependency>
                  <dependency>
                      <groupId>org.projectlombok</groupId>
                      <artifactId>lombok</artifactId>
                      <version>1.18.12</version>
                  </dependency>
                  <dependency>
                      <groupId>com.alibaba</groupId>
                      <artifactId>easyexcel</artifactId>
                      <version>2.2.6</version>
                  </dependency>
              </dependencies>
          </project>
          

          4.2 解析頁面數(shù)據(jù)

          public class BookInfoUtils {
          
              public static List<BookEntity> getBookInfoList(String url) throws IOException {
                  List<BookEntity>  bookEntities=new ArrayList<>();
                  Document doc = Jsoup.connect(url).get();
                  Elements liDiv = doc.select("#content > div > div.article > ul > li");
                  for (Element li : liDiv) {
                      Elements urls = li.select("a[href]");
                      Elements imgUrl = li.select("a > img");
                      Elements bookName = li.select(" div > h2 > a");
                      Elements starsCount = li.select(" div > p.rating > span.font-small.color-lightgray");
                      Elements author = li.select("div > p.color-gray");
                      Elements description = li.select(" div > p.detail");
          
                      String bookDetailUrl = urls.get(0).attr("href");
                      BookDetailInfo detailInfo = getDetailInfo(bookDetailUrl);
                      BookEntity bookEntity = BookEntity.builder()
                              .detailPageUrl(bookDetailUrl)
                              .bookImgUrl(imgUrl.attr("src"))
                              .bookName(bookName.html())
                              .starsCount(starsCount.html())
                              .author(author.text())
                              .bookDetailInfo(detailInfo)
                              .description(description.html())
                              .build();
          //            System.out.println(bookEntity);
                      bookEntities.add(bookEntity);
                  }
                  return bookEntities;
              }
              /**
               *
               * @param detailUrl
               * @return
               * @throws IOException
               */
              public static BookDetailInfo getDetailInfo(String detailUrl)throws IOException{
          
                  Document doc = Jsoup.connect(detailUrl).get();
                  Elements content = doc.select("body");
          
                  Elements price = content.select("#buyinfo-printed > ul.bs.current-version-list > li:nth-child(2) > div.cell.price-btn-wrapper > div.cell.impression_track_mod_buyinfo > div.cell.price-wrapper > a > span");
                  Elements author = content.select("#info > span:nth-child(1) > a");
                  BookDetailInfo bookDetailInfo = BookDetailInfo.builder()
                          .author(author.html())
                          .authorUrl(author.attr("href"))
                          .price(price.html())
                          .build();
                  return bookDetailInfo;
              }
          }
          

          這里的重點是要獲取網(wǎng)頁對應元素的選擇器

          例如:獲取 li.select("div > p.color-gray") 中 div > p.color-gray 是怎么知道的。

          使用 chrome 的小伙伴應該都猜到了。打開 chrome 瀏覽器 Debug 模式,Ctrl + Shift +C 選擇一個元素,然后在 html 右鍵選擇 Copy ->Copy selector,這樣就可以獲取當前元素的選擇器。如下圖:

          4.3 存儲數(shù)據(jù)到 Excel

          為了數(shù)據(jù)更好查看,我將通過 jsoup 抓取的數(shù)據(jù)存儲的 Excel 文件,這里我使用的 easyexcel 快速生成 Excel 文件。

          Excel 表頭信息

          @Data
          @Builder
          public class ColumnData {
          
              @ExcelProperty("書名稱")
              private String bookName;
          
              @ExcelProperty("評分")
              private String starsCount;
          
              @ExcelProperty("作者")
              private String author;
          
              @ExcelProperty("封面圖片")
              private String bookImgUrl;
          
              @ExcelProperty("簡介")
              private String description;
          
              @ExcelProperty("單價")
              private String price;
          }
          

          生成 Excel 文件

          public class EasyExcelUtils {
          
              public static void simpleWrite(List<BookEntity> bookEntityList) {
                  String fileName = "D:\\devEnv\\JsoupTest\\bookList" + System.currentTimeMillis() + ".xlsx";
                  EasyExcel.write(fileName, ColumnData.class).sheet("書本詳情").doWrite(data(bookEntityList));
                  System.out.println("excel文件生成完畢...");
              }
              private static List<ColumnData> data(List<BookEntity> bookEntityList) {
                  List<ColumnData> list = new ArrayList<>();
                  bookEntityList.forEach(b -> {
                      ColumnData data = ColumnData.builder()
                              .bookName(b.getBookName())
                              .starsCount(b.getStarsCount())
                              .author(b.getBookDetailInfo().getAuthor())
                              .bookImgUrl(b.getBookImgUrl())
                              .description(b.getDescription())
                              .price(b.getBookDetailInfo().getPrice())
                              .build();
                      list.add(data);
                  });
                  return list;
              }
          }
          

          4.4 最終展示效果

          最終的效果如下圖:

          以上就是從想法到實踐,我們就在實戰(zhàn)中使用了 jsoup 的基本操作。

          完整代碼地址:https://github.com/hellowHuaairen/JsoupTest

          五、最后

          Java HTML Parser 庫:jsoup,把它當成簡單的爬蟲用起來還是很方便的吧?

          為什么會講爬蟲?大數(shù)據(jù),人工智能時代玩的就是數(shù)據(jù),數(shù)據(jù)很重要。作為懂點技術(shù)的我們,也需要掌握一種獲取網(wǎng)絡(luò)數(shù)據(jù)的技能。當然也有一些工具 Fiddler、webscraper 等也可以抓取你想要的數(shù)據(jù)。

          教程至此,你應該也能對 jsoup 有一些感覺了吧。編程是不是也特別有意思呢?參考我上面的實戰(zhàn)案例,有好多網(wǎng)站可以實踐一下啦~歡迎在評論區(qū)曬你的實戰(zhàn)。

          soup

          抓取網(wǎng)頁后,需要對網(wǎng)頁解析,可以使用字符串處理工具解析頁面,也可以使用正則表達式

          jsoup 的作用:是一款 Java 的HTML 解析器,可直接解析某個URL地址、HTML文本內(nèi)容。它提供了一套非常省力的API,可通過DOM,CSS以及類似于JQuery的操作方法來取出和操作數(shù)據(jù)

          jsoup的主要功能如下:

          1.從一個URL,文件或字符串中解析HTML;

          2.使用DOM或CSS選擇器來查找、取出數(shù)據(jù);

          3.可操作HTML元素、屬性、文本;

          創(chuàng)建練習類

          解析URL

          第一個參數(shù)是訪問的url,第二個參數(shù)是訪問的超時時間

          使用標簽選擇器,獲取title標簽中的內(nèi)容

          輸出結(jié)果

          讀取文件

          準備一個簡易的HTML文件

          獲取這個

          讀取文件,獲取字符串,代碼及結(jié)果

          使用dom方式遍歷文檔

          解析文件獲取document對象

          依據(jù)id獲取,這個是id的內(nèi)容,我們獲取這個內(nèi)容

          編寫代碼,顯示結(jié)果

          依據(jù)標簽獲取,我們獲取這個標簽的內(nèi)容

          代碼及結(jié)果

          依據(jù)class獲取,獲取內(nèi)容

          代碼和結(jié)果

          依據(jù)屬性,屬性內(nèi)容

          代碼和結(jié)果

          接下來從元素中獲取數(shù)據(jù)

          首先從元素中獲取ID

          從元素中獲取className

          文本

          代碼及結(jié)果

          如果內(nèi)容是兩個class

          那么代碼及結(jié)果

          從元素中獲取屬性

          代碼及結(jié)果

          獲取元素的所有屬性

          代碼及結(jié)果

          從元素中獲取文本內(nèi)容,這個之前有,代碼和結(jié)果

          加依賴

                  <!--SpringMVC-->
                  <dependency>
                      <groupId>org.springframework.boot</groupId>
                      <artifactId>spring-boot-starter-web</artifactId>
                  </dependency>
                  <!--SpringData Jpa-->
                  <dependency>
                      <groupId>org.springframework.boot</groupId>
                      <artifactId>spring-boot-starter-data-jpa</artifactId>
                  </dependency>
                  <!--MySQL連接包-->
                  <dependency>
                      <groupId>mysql</groupId>
                      <artifactId>mysql-connector-java</artifactId>
                      <version>5.1.49</version>
                  </dependency>
                  <!-- HttpClient -->
                  <dependency>
                      <groupId>org.apache.httpcomponents</groupId>
                      <artifactId>httpclient</artifactId>
                  </dependency>
                  <!--Jsoup-->
                  <dependency>
                      <groupId>org.jsoup</groupId>
                      <artifactId>jsoup</artifactId>
                       <version>1.15.2</version>
                  </dependency>
                   <!--lombok-->
                  <dependency>
                      <groupId>org.projectlombok</groupId>
                      <artifactId>lombok</artifactId>
                      <optional>true</optional>
                  </dependency>
          復制代碼

          配置application.properties

          # MySQL配置
          spring.datasource.driverClassName=com.mysql.jdbc.Driver
          spring.datasource.url=jdbc:mysql://localhost:3306/demo?useUnicode=true&characterEncoding=utf8
          spring.datasource.username=root
          spring.datasource.password=123456
          
          
          # JPA配置
          spring.jpa.database=MySQL
          spring.jpa.show-sql=true
          spring.jpa.generate-ddl=true
          spring.jpa.hibernate.ddl-auto=update
          spring.jpa.hibernate.naming_strategy=org.hibernate.cfg.ImprovedNamingStrategy
          
          復制代碼

          POJO

          @Entity
          @Table(name = "item")
          @Data
          public class Item {
              @Id
              @GeneratedValue(strategy = GenerationType.IDENTITY)
              private Long id;
              //標準產(chǎn)品單位
              private Long spu;
              //庫存量單位
              private Long sku;
              //商品標題
              private String title;
              //商品價格
              private Double price;
              //商品圖片
              private String pic;
              //商品詳情地址
              private String url;
              //店鋪;
              private String shop;
              //創(chuàng)建時間
              private Date created;
              //更新時間
              private Date updated;
          }
          復制代碼

          Dao

          public interface ItemDao extends JpaRepository<Item,Long> {
          }
          復制代碼

          Service

          public interface ItemService {
          
              /**
               * 保存商品
               *
               * @param item
               */
              void save(Item item);
          
              /**
               * 刪除所有商品
               */
              void deleteAll();
          }
          
          
          @Service
          public class ItemServiceImpl implements ItemService {
          
              @Autowired
              private ItemDao itemDao;
          
              @Override
              @Transactional
              public void save(Item item) {
                  this.itemDao.save(item);
              }
          
              @Override
              public void deleteAll() {
                  this.itemDao.deleteAll();
              }
          }
          復制代碼

          封裝HttpClient

          @Component
          public class HttpUtils {
          
              private static final String FILEPATH = "D:\\demo\\";
          
              private PoolingHttpClientConnectionManager cm;
          
              public HttpUtils() {
                  this.cm = new PoolingHttpClientConnectionManager();
                  //設(shè)置最大連接數(shù)
                  this.cm.setMaxTotal(100);
                  //設(shè)置每個主機的最大連接數(shù)
                  this.cm.setDefaultMaxPerRoute(10);
              }
          
              /**
               * 根據(jù)請求地址下載頁面數(shù)據(jù)
               *
               * @param url
               * @return 頁面數(shù)據(jù)
               */
              public String doGetHtml(String url) {
                  //獲取HttpClient對象
                  CloseableHttpClient httpClient = HttpClients.custom().setConnectionManager(this.cm).build();
                  //創(chuàng)建httpGet請求對象,設(shè)置url地址
                  HttpGet httpGet = new HttpGet(url);
                  httpGet.setHeader("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/103.0.0.0 Safari/537.36");
                  //設(shè)置請求信息
                  httpGet.setConfig(this.getConfig());
                  CloseableHttpResponse response = null;
                  try {
                      //使用HttpClient發(fā)起請求,獲取響應
                      response = httpClient.execute(httpGet);
                      //解析響應,返回結(jié)果
                      if (response.getStatusLine().getStatusCode() == 200) {
                          //判斷響應體Entity是否不為空,如果不為空就可以使用EntityUtils
                          if (response.getEntity() != null) {
                              String content = EntityUtils.toString(response.getEntity(), "utf8");
                              return content;
                          }
                      }
                  } catch (IOException e) {
                      e.printStackTrace();
                  } finally {
                      //關(guān)閉response
                      if (response != null) {
                          try {
                              response.close();
                          } catch (IOException e) {
                              e.printStackTrace();
                          }
                      }
                  }
                  //返回空串
                  return "";
              }
          
          
              /**
               * 下載圖片
               *
               * @param url
               * @return 圖片名稱
               */
              public String doGetImage(String url) {
                  //獲取HttpClient對象
                  CloseableHttpClient httpClient = HttpClients.custom().setConnectionManager(this.cm).build();
                  //創(chuàng)建httpGet請求對象,設(shè)置url地址
                  HttpGet httpGet = new HttpGet(url);
                  //設(shè)置請求信息
                  httpGet.setConfig(this.getConfig());
                  CloseableHttpResponse response = null;
                  try {
                      //使用HttpClient發(fā)起請求,獲取響應
                      response = httpClient.execute(httpGet);
                      //解析響應,返回結(jié)果
                      if (response.getStatusLine().getStatusCode() == 200) {
                          //判斷響應體Entity是否不為空
                          if (response.getEntity() != null) {
                              //獲取圖片的后綴
                              String extName = url.substring(url.lastIndexOf("."));
                              //創(chuàng)建圖片名,重命名圖片
                              String picName = UUID.randomUUID() + extName;
                              //聲明OutPutStream
                              OutputStream outputStream = new FileOutputStream(new File(FILEPATH + picName));
                              response.getEntity().writeTo(outputStream);
                              //返回圖片名稱
                              return picName;
                          }
                      }
          
                  } catch (IOException e) {
                      e.printStackTrace();
                  } finally {
                      //關(guān)閉response
                      if (response != null) {
                          try {
                              response.close();
                          } catch (IOException e) {
                              e.printStackTrace();
                          }
                      }
                  }
                  //如果下載失敗,返回空串
                  return "";
              }
          
              /**
               * 設(shè)置請求信息
               *
               * @return
               */
              private RequestConfig getConfig() {
                  RequestConfig config = RequestConfig.custom()
                          //創(chuàng)建連接的最長時間
                          .setConnectTimeout(1000)
                          // 獲取連接的最長時間
                          .setConnectionRequestTimeout(500)
                          //數(shù)據(jù)傳輸?shù)淖铋L時間
                          .setSocketTimeout(10000)
                          .build();
          
                  return config;
              }
          }
          復制代碼

          SPU與SKU

          SPU

          SPU是商品信息聚合的最小單位,是一組可復用、易檢索的標準化信息的集合,該集合描述了一個產(chǎn)品的特性。

          屬性值、特性相同的商品就可以稱為一個SPU。

          如:某型號某配置某顏色的筆記本電腦就對應一個SPU,它有多種配置,或者多種顏色

          SKU

          SKU即庫存進出計量的單位, 可以是以件、盒、托盤等為單位。SKU是物理上不可分割的最小存貨單元。在使用時要根據(jù)不同業(yè)態(tài),不同管理模式來處理。

          如:某型號的筆記本電腦有多種配置,8G+512G筆記本電腦就是一個SKU。

          爬取分析

          爬取筆記本電腦搜索頁面。進行分頁操作,得到分頁請求地址:https://search.jd.com/search?keyword=%E7%94%B5%E8%84%91&wq=%E7%94%B5%E8%84%91&pvid=56a110735c6c491c91416c194aed4c5b&cid3=672&cid2=671&s=56&click=0&page=

          所有商品由一個class=J_goodsList的div包裹。div中則是由ul標簽包裹的li標簽,每一個li標簽對應一個商品信息。

          li標簽包含的需要的商品信息

          爬取邏輯

          @Component
          public class ItemTask {
          
              @Autowired
              private HttpUtils httpUtils;
              @Autowired
              private ItemService itemService;
          
              /**
               * 使用定時任務(wù)抓取最新數(shù)據(jù)
               *
               * @throws Exception
               */
              @Scheduled(fixedDelay = 50 * 1000)
              public void itemTask() throws Exception {
              	// 每次執(zhí)行前請客數(shù)據(jù)
                  itemService.deleteAll();
                  
                  //聲明需要解析的初始地址
                  String url = "https://search.jd.com/search?keyword=%E7%94%B5%E8%84%91&wq=%E7%94%B5%E8%84%91&pvid=56a110735c6c491c91416c194aed4c5b&cid3=672&cid2=671&s=56&click=0&page=";
          
                  // 按照頁面對搜索結(jié)果進行遍歷解析,注意頁面是奇數(shù)
                  for (int i = 1; i < 10; i = i + 2) {
                      String html = httpUtils.doGetHtml(url + i);
                      // 解析頁面,獲取商品數(shù)據(jù)并存儲
                      this.parse(html);
                  }
                  System.out.println("商品數(shù)據(jù)抓取完成!");
              }
          
              /**
               * 解析頁面,獲取商品數(shù)據(jù)并存儲
               *
               * @param html
               * @throws Exception
               */
              private void parse(String html) {
                  // 解析html獲取Document
                  Document doc = Jsoup.parse(html);
                  // 獲取spu信息
                  Elements spuEles = doc.select("div#J_goodsList > ul > li");
          
                  // 循環(huán)列表中的SPU信息
                  for (int i = 0; i < spuEles.size(); i++) {
                      Element element = spuEles.get(i);
                      //獲取spu
                      String strSpu = element.attr("data-spu");
                      if (strSpu == null || strSpu.equals("")) {
                          continue;
                      }
                      long spu = Long.parseLong(strSpu);
                      //獲取sku
                      long sku = Long.parseLong(element.attr("data-sku"));
          
                      Item item = new Item();
                      //設(shè)置商品的spu
                      item.setSpu(spu);
                      //設(shè)置商品的sku
                      item.setSku(sku);
                      //獲取商品的詳情的url
                      String itemUrl = "https://item.jd.com/" + sku + ".html";
                      item.setUrl(itemUrl);
          
                      // 獲取商品的圖片
                      String picUrl = "https:" + element.select("div.p-img").select("a").select("img").attr("data-lazy-img");
                      String picName = this.httpUtils.doGetImage(picUrl);
                      item.setPic(picName);
          
                      //獲取商品的價格
                      String strPrice = element.select("div.p-price").select("i").text();
                      item.setPrice(Double.parseDouble(strPrice));
          
                      //獲取商品的標題
                      String title = element.select("div.p-name").select("a").attr("title");
                      item.setTitle(title);
          
                      // 店鋪名稱
                      String shopName = element.select("div.p-shop a").text();
                      item.setShop(shopName);
          
                      item.setCreated(new Date());
                      item.setUpdated(item.getCreated());
          
                      //保存商品數(shù)據(jù)到數(shù)據(jù)庫中
                      this.itemService.save(item);
                  }
              }
          }
          復制代碼

          配置啟動類

          @SpringBootApplication
          // 開啟定時任務(wù)
          @EnableScheduling
          public class Application {
              public static void main(String[] args) {
                  SpringApplication.run(Application.class, args);
              }
          }
          復制代碼

          執(zhí)行測試

          啟動項目,執(zhí)行測試。查看數(shù)據(jù)庫與本地下載照片。


          主站蜘蛛池模板: 国产亚洲福利一区二区免费看| 日韩人妻无码一区二区三区 | 日韩精品一区二区三区不卡 | 国产在线不卡一区| 无码中文人妻在线一区二区三区 | 国产伦精品一区二区三区免费迷 | 日本一区二区免费看| 日韩精品无码一区二区中文字幕| 亚洲一区二区三区久久久久| 亚洲日本久久一区二区va| 日本一区二区三区四区视频| 亚洲Aⅴ无码一区二区二三区软件 亚洲AⅤ视频一区二区三区 | 国产精品免费大片一区二区| 天堂资源中文最新版在线一区 | 国内精品视频一区二区三区| 日本一区二区三区不卡视频中文字幕| 精品久久久久一区二区三区| 人妻AV中文字幕一区二区三区 | 亚洲日韩国产一区二区三区在线| 日韩精品一区在线| 波多野结衣免费一区视频| 丝袜美腿一区二区三区| 国精品无码一区二区三区在线| 无码中文字幕一区二区三区| 丰满少妇内射一区| 精品国产免费一区二区| 无码AV中文一区二区三区| 无码欧精品亚洲日韩一区夜夜嗨 | 久久国产午夜精品一区二区三区| 91福利视频一区| 国产精品亚洲不卡一区二区三区| 亚洲字幕AV一区二区三区四区| 久久99久久无码毛片一区二区| 国产精品av一区二区三区不卡蜜| 国产色综合一区二区三区| 日韩在线视频不卡一区二区三区| 亚洲国产精品乱码一区二区| 国产丝袜无码一区二区视频| 亚洲福利一区二区三区| 亚洲日韩精品一区二区三区无码| 日韩在线观看一区二区三区|