最近看到Gecoo爬虫工具,感觉比较简单好用,所有写个DEMO测试一下,抓取网站
http://zj.zjol.com.cn/home.html,主要抓取新闻的标题和发布时间做为抓取测试对象。抓取HTML节点通过像Jquery选择器一样选择节点,非常方便,Gecco代码主要利用注解实现来实现URL匹配,看起来比较简洁美观。
添加Maven依赖
com.geccocrawler
gecco
1.0.8
编写抓取列表页面
@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 = "#content > div > div > div.con_index > div.r.main_mod > div > ul > li > dl > dt > a")
private List newList;
}
@P