美文网首页
Gecco文档-首页

Gecco文档-首页

作者: 4ea0af17fd67 | 来源:发表于2018-07-02 11:28 被阅读51次

Gecco是什么

Gecco是一款用java语言开发的轻量化的易用的网络爬虫。Gecco整合了jsoup、httpclient、fastjson、spring、htmlunit、redission等优秀框架,让您只需要配置一些jquery风格的选择器就能很快的写出一个爬虫。Gecco框架有优秀的可扩展性,框架基于开闭原则进行设计,对修改关闭、对扩展开放。同时Gecco基于十分开放的MIT开源协议,无论你是使用者还是希望共同完善Gecco的开发者,欢迎pull request。如果你喜欢这款爬虫框架请star 或者 fork!

主要特征

  • 简单易用,使用jquery风格的选择器抽取元素
  • 支持爬取规则的动态配置和加载
  • 支持页面中的异步ajax请求
  • 支持页面中的javascript变量抽取
  • 利用Redis实现分布式抓取,参考gecco-redis
  • 支持结合Spring开发业务逻辑,参考gecco-spring
  • 支持htmlunit扩展,参考gecco-htmlunit
  • 支持插件扩展机制
  • 支持下载时UserAgent随机选取
  • 支持下载代理服务器随机选取

快速开始

@Gecco(matchUrl="https://github.com/{user}/{project}", pipelines="consolePipeline")
public class MyGithub implements HtmlBean {

    private static final long serialVersionUID = -7127412585200687225L;

    @RequestParameter("user")
    private String user;//url中的{user}值

    @RequestParameter("project")
    private String project;//url中的{project}值

    @Text
    @HtmlField(cssPath=".repository-meta-content")
    private String title;//抽取页面中的title

    @Text
    @HtmlField(cssPath=".pagehead-actions li:nth-child(2) .social-count")
    private int star;//抽取页面中的star

    @Text
    @HtmlField(cssPath=".pagehead-actions li:nth-child(3) .social-count")
    private int fork;//抽取页面中的fork

    @Html
    @HtmlField(cssPath=".entry-content")
    private String readme;//抽取页面中的readme

    public String getReadme() {
        return readme;
    }

    public void setReadme(String readme) {
        this.readme = readme;
    }

    public String getUser() {
        return user;
    }

    public void setUser(String user) {
        this.user = user;
    }

    public String getProject() {
        return project;
    }

    public void setProject(String project) {
        this.project = project;
    }

    public String getTitle() {
        return title;
    }

    public void setTitle(String title) {
        this.title = title;
    }

    public int getStar() {
        return star;
    }

    public void setStar(int star) {
        this.star = star;
    }

    public int getFork() {
        return fork;
    }

    public void setFork(int fork) {
        this.fork = fork;
    }

    public static void main(String[] args) {
        GeccoEngine.create()
        //工程的包路径
        .classpath("com.geccocrawler.gecco.demo")
        //开始抓取的页面地址
        .start("https://github.com/xtuhcy/gecco")
        //开启几个爬虫线程
        .thread(1)
        //单个爬虫每次抓取完一个请求后的间隔时间
        .interval(2000)
        //循环抓取
        .loop(true)
        //使用pc端userAgent
        .mobile(false)
        //开始运行
        .run();
    }
}

DynamicGecco

DynamicGecco的目的是在不定义SpiderBean的情况下实现爬取规则的运行时配置。其实现原理是采用字节码编程,动态生成SpiderBean,而且通过自定义的GeccoClassLoader实现了抓取规则的热部署。下面是一个简单Demo,更复杂的Demo可以参考com.geccocrawler.gecco.demo.dynamic下的例子。

下面的代码实现了爬取规则的运行时配置:

DynamicGecco.html()
.gecco("https://github.com/{user}/{project}", "consolePipeline")
.requestField("request").request().build()
.stringField("user").requestParameter("user").build()
.stringField("project").requestParameter().build()
.stringField("title").csspath(".repository-meta-content").text(false).build()
.intField("star").csspath(".pagehead-actions li:nth-child(2) .social-count").text(false).build()
.intField("fork").csspath(".pagehead-actions li:nth-child(3) .social-count").text().build()
.stringField("contributors").csspath("ul.numbers-summary > li:nth-child(4) > a").href().build()
.register();

//开始抓取
GeccoEngine.create()
.classpath("com.geccocrawler.gecco.demo")
.start("https://github.com/xtuhcy/gecco")
.run();

可以看到,DynamicGecco的方式相比传统的注解方式代码量大大减少,而且很酷的一点是DynamicGecco支持运行时定义和修改规则。

交流联系

开源协议

请遵守开源协议MIT

相关文章

  • Gecco文档-首页

    Gecco是什么 Gecco是一款用java语言开发的轻量化的易用的网络爬虫。Gecco整合了jsoup、http...

  • gecco 的学习和练习

    1,学习gecco源码地址:https://gitee.com/xtuhcy/gecco[https://gite...

  • 需要些例子

    教您使用java爬虫gecco抓取JD全部商品信息教您使用DynamicGecco抓取JD全部商品信息 Gecco...

  • 使用手册

    一、Gecco是什么 Gecco是一款用java语言开发的轻量化的易用的网络爬虫,不同于Nutch这样的面向搜索引...

  • SV检测软件使用总结

    Manta star:193 update:2019-06-25 link 首页 文档 install 中文文档 ...

  • 凑字1

    上亿文档资料,等你来发现 三亿文库 设为首页收藏本站 窗体顶端 亿万文档,必有所需 窗体底端 首页考试资料幻灯片工...

  • gRPC资料合集

    官方文档中文版 osc众包翻译版 质量很不错,良心之举 官方文档 文档首页 快速入门JavapythonAndro...

  • 把玩爬虫框架Gecco

    如果你现在接到一个任务,获取某某行业下的分类。 作为一个非该领域专家,没有深厚的运营经验功底,要提供一套摆的上台面...

  • 春节大礼,Vite2.0 正式发布,中文手册同步更新

    ? Vite 中文文档祝全体读者 2021 春节快乐! ? 打开 github 的 vite 中文文档首页,首先看...

  • (Vue -01)初始Vue + Vue的响应式原理(使用Obj

    Vue官方文档=>>>首页-学习下拉栏-文档-教程 =>火速一键进入学习[https://cn.vuejs.o...

网友评论

      本文标题:Gecco文档-首页

      本文链接:https://www.haomeiwen.com/subject/fvwkuftx.html