【发布时间】:2022-01-23 14:39:26
【问题描述】:
GoColly 执行网络请求的默认模式是什么?由于我们在收集器中有Async 方法,我假设默认模式是同步的。
但是,当我在程序中执行这 8 个请求时,除了我需要使用 Wait 进行异步模式外,我没有发现特别的区别。似乎该方法只控制程序的执行方式(其他代码),并且请求始终是异步的。
package main
import (
"fmt"
"github.com/gocolly/colly/v2"
)
func main() {
urls := []string{
"http://webcode.me",
"https://example.com",
"http://httpbin.org",
"https://www.perl.org",
"https://www.php.net",
"https://www.python.org",
"https://code.visualstudio.com",
"https://clojure.org",
}
c := colly.NewCollector(
colly.Async(true),
)
c.OnHTML("title", func(e *colly.HTMLElement) {
fmt.Println(e.Text)
})
for _, url := range urls {
c.Visit(url)
}
c.Wait()
}
【问题讨论】:
标签: go asynchronous go-colly