项目详情
由
分享
HelloGitHub 评分
0 人评分
开源•MPL-2.0
认领
讨论
收藏
分享
2.8k
星数
否
中文
Go
主语言
否
活跃
1
贡献者
30
Issues
是
组织
无
最新版本
157
Forks
MPL-2.0
协议
更多
Go 的分布式爬虫框架。示例代码:
```go
func main() {
geziyor.NewGeziyor(&geziyor.Options{
StartURLs: []string{"http://quotes.toscrape.com/"},
ParseFunc: quotesParse,
// exporter 可以用来把最终结果存成各种格式,例如 json
Exporters: []geziyor.Exporter{exporter.JSONExporter{}},
}).Start()
}
// 请求的结果直接进了一个管道处理函数,这样的函数可以串联起来,爬虫和清洗二合一
// 这样拆分爬虫逻辑,某些逻辑也可以重用
func quotesParse(g *geziyor.Geziyor, r *geziyor.Response) {
r.HTMLDoc.Find("div.quote").Each(func(i int, s *goquery.Selection) {
g.Exports <- map[string]interface{}{
"text": s.Find("span.text").Text(),
"author": s.Find("small.author").Text(),
}
})
if href, ok := r.HTMLDoc.Find("li.next > a").Attr("href"); ok {
g.Get(r.JoinURL(href), quotesParse)
}
}
```
收录于:
第 39 期
评论
评分:
暂无精选评论