<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 = "#content > div > div > div.con_index > div.r.main_mod > div > ul > li > dl > dt > a")
private List<HrefBean> newList;
}
@PipelineName("zJNewsListPipelines")
public class ZJNewsListPipelines implements Pipeline<ZJNewsGeccoList> {
public void process(ZJNewsGeccoList zjNewsGeccoList) {
HttpRequest request=zjNewsGeccoList.getRequest();
for (HrefBean bean:zjNewsGeccoList.getNewList()){
//进入祥情页面抓取
SchedulerContext.into(request.subRequest("http://zj.zjol.com.cn"+bean.getUrl()));
}
int page=zjNewsGeccoList.getPageIndex()+1;
String nextUrl = "http://zj.zjol.com.cn/home.html?pageIndex="+page+"&pageSize=100";
//抓取下一页
SchedulerContext.into(request.subRequest(nextUrl));
}
}
@Gecco(matchUrl = "http://zj.zjol.com.cn/news/[code].html" ,pipelines = "zjNewsDetailPipeline")
public class ZJNewsDetail implements HtmlBean {
@Text
@HtmlField(cssPath = "#headline")
private String title ;
@Text
@HtmlField(cssPath = "#content > div > div.news_con > div.news-content > div:nth-child(1) > div > p.go-left.post-time.c-gray")
private String createTime;
}
@PipelineName("zjNewsDetailPipeline")
public class ZJNewsDetailPipeline implements Pipeline<ZJNewsDetail> {
public void process(ZJNewsDetail zjNewsDetail) {
System.out.println(zjNewsDetail.getTitle()+" "+zjNewsDetail.getCreateTime());
}
}
public class Main {
public static void main(String [] rags){
GeccoEngine.create()
//工程的包路径
.classpath("com.zhaochao.gecco.zj")
//开始抓取的页面地址
.start("http://zj.zjol.com.cn/home.html?pageIndex=1&pageSize=100")
//开启几个爬虫线程
.thread(10)
//单个爬虫每次抓取完一个请求后的间隔时间
.interval(10)
//使用pc端userAgent
.mobile(false)
//开始运行
.run();
}
}
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有