2021SC@SDUSC
最近分析Gecco的爬虫代码,决定写个DEMO测试一下,也方便更好的分析其源代码,抓取网站
http://zj.zjol.com.cn/home.html,主要抓取新闻的标题和发布时间做为抓取测试对象。抓取HTML节点通过像Jquery选择器一样选择节点,非常方便,Gecco代码主要利用注解实现来实现URL匹配,看起来比较简洁美观。
添加Maven依赖
<dependency>
<groupId>com.geccocrawler</groupId>
<artifactId>gecco</artifactId>
<version>1.0.8</version>
</dependency>
编写抓取列表页面
@Gecco(matchUrl = "http://zj.zjol.com.cn/home.html?pageIndex={pageIndex}&pageSize={pageSize}",pipelines = "zJNewsListPipelines")
public class ZJNewsGeccoList implements HtmlBean {
@Request
private HttpRequest request;
@RequestParameter
private int pageIndex;
@RequestParameter
private int pageSize;
@HtmlField(cssPath =