{"id":19993231,"url":"https://github.com/heyingcai/cetty","last_synced_at":"2025-05-04T12:31:02.390Z","repository":{"id":34294801,"uuid":"146616099","full_name":"heyingcai/cetty","owner":"heyingcai","description":"基于事件分发的爬虫框架","archived":false,"fork":false,"pushed_at":"2022-09-01T22:44:21.000Z","size":125,"stargazers_count":36,"open_issues_count":5,"forks_count":11,"subscribers_count":4,"default_branch":"master","last_synced_at":"2024-11-13T04:56:09.167Z","etag":null,"topics":["crawler","event-dispatcher","gather","spider"],"latest_commit_sha":null,"homepage":"","language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/heyingcai.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-08-29T14:55:31.000Z","updated_at":"2021-12-11T08:22:55.000Z","dependencies_parsed_at":"2022-09-17T15:00:37.498Z","dependency_job_id":null,"html_url":"https://github.com/heyingcai/cetty","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/heyingcai%2Fcetty","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/heyingcai%2Fcetty/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/heyingcai%2Fcetty/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/heyingcai%2Fcetty/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/heyingcai","download_url":"https://codeload.github.com/heyingcai/cetty/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252334242,"owners_count":21731366,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["crawler","event-dispatcher","gather","spider"],"created_at":"2024-11-13T04:52:32.233Z","updated_at":"2025-05-04T12:30:57.370Z","avatar_url":"https://github.com/heyingcai.png","language":"Java","funding_links":[],"categories":["Java"],"sub_categories":[],"readme":"# Cetty\n\n一个轻量级的基于事件分发的爬虫框架。\n\n[![Build Status](https://www.travis-ci.org/heyingcai/cetty.svg?branch=master)](https://travis-ci.org/heyingcai/cetty)\n[![License](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](https://github.com/dempeZheng/forest/blob/master/LICENSE)\n[![](https://img.shields.io/badge/language-java-yellowgreen.svg)](https://img.shields.io/badge/language-java-yellowgreen.svg)\n\n\n\u003eAn event dispatch crawler framework. \n\n![](https://s1.ax1x.com/2018/11/12/iOAjG8.png)\n\n## 功能介绍\n* 基于完全自定义事件处理机制的爬虫框架。\n* 模块化的设计，提供强大的可扩展性。\n* 基于HttpClient支持同步和异步数据抓取。\n* 支持多线程。\n* 基于Jsoup页面解析框架提供强大的网页解析处理能力。\n\n## 快速开始\n### 使用Maven\n```xml\n\u003cdependency\u003e\n  \u003cgroupId\u003ecom.jibug.cetty\u003c/groupId\u003e\n  \u003cartifactId\u003ecetty-core\u003c/artifactId\u003e\n  \u003cversion\u003e0.1.8\u003c/version\u003e\n\u003c/dependency\u003e\n```\n\n## 帮助\n1.详细文档：[http://cetty.jibug.com/](http://cetty.jibug.com/) \u003cbr\u003e\n2.QQ群 \u003cbr\u003e\n![](https://s1.ax1x.com/2018/11/20/F9GsFs.png)\u003cbr\u003e\n3.bug反馈：[issues](https://github.com/heyingcai/cetty/issues)\n\n## 让我们来写第一个demo\n\n```java\n/**\n * 抓取天涯论坛文章列表标题\n * http://bbs.tianya.cn/list-333-1.shtml\n *\n * @author heyingcai\n */\npublic class Tianya extends ProcessHandlerAdapter {\n\n    @Override\n    public void process(HandlerContext ctx, Page page) {\n        //获取 Document\n        Document document = page.getDocument();\n        //dom解析\n        Elements itemElements = document.\n                select(\"div#bbsdoc\u003ediv#bd\u003ediv#main\u003ediv.mt5\u003etable\u003etbody\").\n                get(2).\n                select(\"tr\");\n        List\u003cString\u003e titles = Lists.newArrayList();\n        for (Element item : itemElements) {\n            String title = item.select(\"td.td-title\").text();\n            titles.add(title);\n        }\n\n        //获取Result对象，将我们解析出来的结果向下一个handler传递\n        Result result = page.getResult();\n        result.addResults(titles);\n        \n        //通过fireXXX 方法将本handler 处理的结果向下传递\n        //本教程直接将结果传递给ConsoleHandler，将结果直接输出控制台\n        ctx.fireReduce(page);\n    }\n\n    public static void main(String[] args) {\n        //启动引导类\n        Bootstrap.\n                me()\n                //使用同步抓取\n                .isAsync(false)\n                //开启一个线程\n                .setThreadNum(1)\n                //抓取入口url\n                .startUrl(\"http://bbs.tianya.cn/list-333-1.shtml\")       \n                //通用请求信息\n                .setPayload(Payload.custom())       \n                //添加自定处理器\n                .addHandler(new Tianya())        \n                //添加默认结果处理器，输出至控制台\n                .addHandler(new ConsoleReduceHandler())\n                //是否启用实时抓取模式，如果启用非实时抓取模式则当任务队列中没有任务的一段时间后爬虫会自动处于close状态\n                .isDuration(false)\n                .start();\n    }\n}\n```\n\n## 历史版本\n\n| 版本      | 说明   |\n| :----:   | :----:   |\n| 0.1.0    | 支持基本爬虫功能|\n| 0.1.5    | 1.支持xpath 2.修复添加cookie失效问题 3.优化底层逻辑 |\n| 0.1.7    | 修复底层bug | \n\n\n## TODO\n\n* 支持注解方式\n* 支持代理池\n* 支持Berkeley 内存数据作为url管理器，提供海量url存储并提高存取效率\n* 支持热更新\n* 支持爬虫治理\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fheyingcai%2Fcetty","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fheyingcai%2Fcetty","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fheyingcai%2Fcetty/lists"}