package main

import (
	"fmt"

	"github.com/gocolly/colly"
)

func main() {
	c := colly.NewCollector()

	c.OnHTML(".sidebar-link", func(e *colly.HTMLElement) {
		href := e.Attr("href")
		if href != "index.html" {
			c.Visit(e.Request.AbsoluteURL(href))
		}
	})

	c.OnHTML(".article-title", func(h *colly.HTMLElement) {
		title := h.Text
		fmt.Printf("title: %v\n", title)
	})

	c.OnHTML(".article", func(h *colly.HTMLElement) {
		content, _ := h.DOM.Html()
		fmt.Printf("content: %v\n", content)
	})

	c.OnRequest(func(r *colly.Request) {
		fmt.Println("Visiting", r.URL.String())
	})

	c.Visit("https://gorm.io/zh_CN/docs/")
}

1、使用colly框架重构后的爬虫应用能否实现多线程运行?怎么改? 2、项目特性中的 同步/异步/并行抓取 是指的什么?

清晰明了的 API
速度快(单个内核上的请求数大于1k)
管理每个域的请求延迟和最大并发数
自动 cookie 和会话处理
同步/异步/并行抓取
高速缓存
自动处理非 Unicode 编码
支持 Robots.txt
支持 Google App Engine
通过环境变量进行配置
可扩展