使用闭包函数的类 Scrapy 的 Go 爬虫框架——Goribot
https://github.com/zhshch2002/goribot
- Goroutine原生支持并发
- 使用匿名函数实现蜘蛛处理逻辑
- 使用Pipeline插入生命周期钩子实现扩展
- 已经实现了部分常用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()
}