分享
这是一个创建于 的主题,其中的信息可能已经有所发展或是发生改变。
项目地址:[https://github.com/zhshch2002/goribot](https://github.com/zhshch2002/goribot)
使用文档:[https://imagician.net/goribot/](https://imagician.net/goribot/)
## Feature
* 优雅的 API
* 整洁的文档
* 高速(单核处理 >1K task/sec)
* 友善的分布式支持
* 丰富的扩展支持
* 请求去重(????支持分布式)
* 限制请求、速率、并发
* Json,CSV 存储结果
* Robots.txt 支持
* 记录请求异常
* 随机 UA 、随机代理
* 失败重试
* 轻量,适于学习或快速开箱搭建
## Demo
```go
package main
import (
"fmt"
"github.com/PuerkitoBio/goquery"
"github.com/zhshch2002/goribot"
)
func main() {
s := goribot.NewSpider() // 创建了一个爬虫
var h goribot.CtxHandlerFun // 这是一个回调函数,用于发现新链接(不把他用 var 单出来声明就没法在回调函数内调用自己)
h = func(ctx *goribot.Context) {
fmt.Println(ctx.Resp.Request.URL)
if ctx.Resp.Dom != nil {
ctx.Resp.Dom.Find("a").Each(func(i int, sel *goquery.Selection) {
if u := sel.AttrOr("href", ""); u !="" {
// ???? 注意在这里不是 s.AddTask 而是 ctx.AddTask
ctx.AddTask(goribot.GetReq(u), h)
}
})
}
}
// 使用回调函数 h 来创建种子任务
s.AddTask(goribot.GetReq("https://httpbin.org"), h)
s.Run()
}
```
## 分布式爬虫
[一键开启 Goribot 的分布式模式!](https://imagician.net/goribot/distributed.html)
有疑问加站长微信联系(非本文作者)
入群交流(和以上内容无关):加入Go大咖交流群,或添加微信:liuxiaoyan-s 备注:入群;或加QQ群:692541889
关注微信2922 次点击
添加一条新回复
(您需要 后才能回复 没有账号 ?)
- 请尽量让自己的回复能够对别人有帮助
- 支持 Markdown 格式, **粗体**、~~删除线~~、
`单行代码` - 支持 @ 本站用户;支持表情(输入 : 提示),见 Emoji cheat sheet
- 图片支持拖拽、截图粘贴等方式上传