forked from go/golangs_learn
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
27 lines
471 B
27 lines
471 B
2 years ago
|
package main
|
||
|
|
||
|
import (
|
||
|
"log"
|
||
|
|
||
|
"github.com/gocolly/colly"
|
||
|
)
|
||
|
|
||
|
func main() {
|
||
|
// create a new collector
|
||
|
c := colly.NewCollector()
|
||
|
|
||
|
// authenticate
|
||
|
err := c.Post("http://example.com/login", map[string]string{"username": "admin", "password": "admin"})
|
||
|
if err != nil {
|
||
|
log.Fatal(err)
|
||
|
}
|
||
|
|
||
|
// attach callbacks after login
|
||
|
c.OnResponse(func(r *colly.Response) {
|
||
|
log.Println("response received", r.StatusCode)
|
||
|
})
|
||
|
|
||
|
// start scraping
|
||
|
c.Visit("https://example.com/")
|
||
|
}
|