使用闭包函数的类 Scrapy 的 Go 爬虫框架——Goribot

https://github.com/zhshch2002/goribot

  • Goroutine 原生支持并发
  • 使用匿名函数实现蜘蛛处理逻辑
  • 使用 Pipeline 插入生命周期钩子实现扩展

README 里有完整的 Bilibili 爬虫实例。使用了 Pipeline 和闭包函数的设计。
简单实例:

package main

import (
    "encoding/json"
    "fmt"
    "github.com/zhshch2002/goribot"
)

func main() {
    s := goribot.NewSpider()
    _ = s.Get(nil, "https://httpbin.org/get?Goribot%20test=hello%20world", func(r *goribot.Response) {
        m := make(map[string]interface{})
        err := json.Unmarshal([]byte(r.Text), &m)
        if err != nil {
            fmt.Println(err)
        }
        fmt.Println(m)
    })
    s.Run()
}