-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
38 lines (31 loc) · 1007 Bytes
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
package main
import (
"fmt"
"log"
"github.com/gocolly/colly"
)
func main() {
// Instantiate default collector
c := colly.NewCollector(
// Visit only domains: hackerspaces.org, wiki.hackerspaces.org
//colly.AllowedDomains("twitter.com"),
)
// On every a element which has href attribute call callback
c.OnHTML("div", func(e *colly.HTMLElement) {
link := e.Attr("href")
// Print link
fmt.Printf("Link found: %q -> %s\n", e.Text, link)
// Visit link found on page
// Only those links are visited which are in AllowedDomains
//c.Visit(e.Request.AbsoluteURL(link))
})
// Before making a request print "Visiting ..."
c.OnRequest(func(r *colly.Request) {
fmt.Println("Visiting", r.URL.String())
})
c.OnError(func(_ *colly.Response, err error) {
log.Println("Something went wrong:", err)
})
// Start scraping on https://hackerspaces.org
c.Visit("https://twitter.com/search?q=%23suicidio%20geocode%3A42.4%2C-3.7%2C650km%20since%3A2019-05-01%20until%3A2019-05-05&src=typd")
}