forked from JackOddy/web-crawler
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
46 lines (39 loc) · 726 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
39
40
41
42
43
44
45
46
package main
import (
"flag"
tags "golang.org/x/net/html/atom"
"golang.org/x/sync/syncmap"
)
var (
VisitedLinks = syncmap.Map{}
Domain = flag.String("u", "", "Domain")
Scrapable = map[tags.Atom]bool{
tags.A: true,
tags.Img: true,
tags.Script: true,
tags.Link: true,
}
)
func main() {
flag.Parse()
firstLink := Link{*Domain, true}
links := make(chan Link)
pages := make(chan Page)
errors := make(chan bool)
go Crawl(firstLink, links, pages, errors)
n := 1
for n > 0 {
select {
case link := <-links:
if link.ShouldCrawl(Domain) {
go Crawl(link, links, pages, errors)
n++
}
case page := <-pages:
go page.Report()
n--
case _ = <-errors:
n--
}
}
}