#676·colly

异步和队列

作者: billiboy创建于 2022年1月17日更新于 2025年3月7日

"Scraper 函数":

`c := colly.NewCollector(

	colly.MaxDepth(30),
	colly.Async(true),
)
c.Limit(&colly.LimitRule{
	Parallelism: 100,
	RandomDelay: 6 * time.Second,
})
c.SetRequestTimeout(120 * time.Second)
c.WithTransport(&http.Transport{
	DisableKeepAlives: true,
})

c.OnHTML("a.SmallCard-module_link__9Ey4a.link", func(e *colly.HTMLElement) {

	l := e.Attr("href")

	if l != "" {
		fmt.Println("Url", l)
	}

})

c.OnHTML(`a.index-module_link__PZ2VK.index-module_outline__2EfuB.index-module_medium__2lAkR.pagination_arrow-button__Y0iWq`, func(e *colly.HTMLElement) {

	e.Request.Visit(e.Attr("href"))

})

c.OnError(func(r *colly.Response, err error) {
	
		fmt.Println("Request URL:", r.Request.URL, "failed with response:", r, "\nError:", err)
	
})


c.Visit(url)
c.Wait()
wg.Done()`

我无法判断我的做法是否正确,我不满意速度。你建议我怎么做?我想让它性能良好且稳定。