In [1]:
import "github.com/gocolly/colly"
In [2]:
c := colly.NewCollector()
In [3]:
c.OnRequest(func(r *colly.Request) {
fmt.Println("Visiting", r.URL)
})
c.OnError(func(_ *colly.Response, err error) {
log.Println("Something went wrong:", err)
})
c.OnResponse(func(r *colly.Response) {
fmt.Println("Visited", r.URL)
})
c.OnHTML("a[href]", func(e *colly.HTMLElement) {
e.Request.Visit(e.Attr("href"))
})
c.OnHTML("tr td:nth-of-type(1)", func(e *colly.HTMLElement) {
fmt.Println("First column of a table row:", e.Text)
})
c.OnScraped(func(r *colly.Response) {
fmt.Println("Finished", r.URL)
})
In [5]:
c.Visit('https://mylesb.ca/')
In [ ]: