최근에 간단하고 사용하기 쉬운 Gecoo Crawler 도구를 보았습니다. 데모 테스트를 작성하고 웹 사이트를 크롤링하십시오.
http://zj.zjol.com.cn/home.html, 주로 뉴스의 제목과 출시 시간을 크롤링 테스트 개체로 기어 다닙니다. JQuery Selectors와 같은 노드를 선택하여 HTML 노드를 크롤링하는 것이 매우 편리합니다. GECCO 코드는 주로 주석 구현을 사용하여 URL 매칭을 달성하는데, 이는 비교적 간결하고 아름답게 보입니다.
Maven 의존성을 추가하십시오
<pectionency> <groupid> com.geccacrawler </groupid> <artifactid> gecco </artifactid> <버전> 1.0.8 </version> </fectionency>
크롤링 목록 페이지를 작성하십시오
@gecco (matchurl = "http://zj.zjol.com.cn/home.html?pageindex= {pageindex }&pagesize= {pagesize }",pipelines ="zjnewslistpipelines ") public zjnewsgeccolist htmlbean htmlbean htmlbean htmlbean emprivate htmlbean htmlbeant; @requestparameter private int pageindex; @requestparameter private int pageize; @htmlfield (csspath = "#content> div> div> div.con_index> div.r.main_mod> div> ul> li> dl> dt> a") 개인 목록 <hrefbean> newlist;} @pipelinename ( "zjnewslistpipelines") public class zjnewslistpipelines는 파이프 라인 <zjnewsgeccolist> {public void process (zjnewsgeccolist zjnewsgeccolist) {httprequest 요청 = zjnewsgeccolist.getRequesccolist (getRequesccolist); for (hrefbean bean : zjnewsgeccolist.getnewlist ()) {// spellyercontext.into (request.subrequest ( "http://zj.zjol.com.cn"+bean.geturl ())를 크롤링하기 위해 상서로운 페이지를 입력합니다. } int page = zjnewsgeccolist.getPageIndex ()+1; 문자열 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/=Cnews/=Cnews/] .html", Pipelines = "ZjnewsDetailPipeline") 공개 클래스 zjnewsdetail htmlbean {@text @htmlfield (csspath = ") 개인 문자열; @Text @htmlfield (csspath = "#content> div> div.news_con> div.news-content> div : nth-Child (1)> div> p.go-left.post-time.c-gray") 개인 문자열 createTime;} @pipelinename ( "zjnewsdetailpipeline") public class zjnewsdetailpipeline은 파이프 라인 <zjnewsdetail> {public void process (zjnewsDetail zjnewsDetail) {system.out.out.println (zjnewsdetail.gettitle ()+" "+zjnewsdetail.getCreateTime ()); }} 기본 기능을 시작하십시오
public class main {public static void main (string [] rags) {geccoengine.create () // project.classpath의 패키지 경로 ( "com.zhaochao.gecco.zj") // crawling.start를 시작하는 페이지 주소 ( "http://zj.zjol.com.cn/home.home.pageing=11/home.pageindex=11/Home.html? // 여러 크롤러 스레드를 엽니 다. thread (10) // 요청을 크롤링 한 후 단일 크롤러 사이의 간격. }}크롤링 결과
위는이 기사의 모든 내용입니다. 모든 사람의 학습에 도움이되기를 바랍니다. 모든 사람이 wulin.com을 더 지원하기를 바랍니다.