菜单 学习猿地 - LMONKEY

VIP

开通学习猿地VIP

尊享10项VIP特权 持续新增

知识通关挑战

打卡带练!告别无效练习

接私单赚外块

VIP优先接,累计金额超百万

学习猿地私房课免费学

大厂实战课仅对VIP开放

你的一对一导师

每月可免费咨询大牛30次

领取更多软件工程师实用特权

入驻
3052
0

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

原创
05/13 14:22
阅读数 3186

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()
}

发表评论

0/200
3052 点赞
0 评论
收藏
为你推荐 换一批