Bootstrap

crawler爬虫demo, 基于gecco

今天我们来写一下基于gecco的爬虫例子。

当然还是以"x东"页面为例,链接:https://www.jd.com。

首先我们主要需要gecco包:

       <dependency>
 <groupId>com.geccocrawler</groupId>
   <artifactId>gecco</artifactId>
   <version>1.2.8</version>
</dependency>

好了,我们来不如正题吧!

先创建一个类(CatalogItemModel)有这两个:

       @Text
@HtmlField(cssPath = "a")
private String title;

@Attr("href")
@HtmlField(cssPath = "a")
private String href;

这是指定爬取a链接;

在创建CatalogTopModel类:

       @HtmlField(cssPath ="a.cate_menu_lk")
private List<CatalogItemModel> items;

public List<CatalogItemModel> getItems() {
return items;
}

public void setItems(List<CatalogItemModel> items) {
this.items = items;

;