-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
64 lines (53 loc) · 1.24 KB
/
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
package main
import (
"fmt"
"os"
"pathfinder/src/cli"
"pathfinder/src/crawler"
"pathfinder/src/store"
"pathfinder/src/workers"
"time"
)
/*
TODO:
- proxy
- interrupt ctrl+c
- change slice to map
*/
func runInitScrap(c *crawler.Crawler, s *store.ScrapStore) {
s.AddUrl(*c.RootUrl())
url, _ := s.GetNextUrlToVisit()
collector := c.NewCollector()
urls := c.ScrapUrlsFromUrl(collector, url)
s.IncrementVisits()
for _, v := range urls {
s.AddUrl(v)
}
}
func showStats(s *store.ScrapStore, start time.Time) {
fmt.Println()
fmt.Printf("Pages visited: %v\n", s.Visits())
fmt.Printf("URLs scraped: %v\n", s.CountScrapedUrls())
fmt.Printf("Elapsed time : %v\n", time.Since(start))
}
func start(flags *cli.Flags) {
startTime := time.Now()
c := crawler.NewCrawler(flags.Url, flags.NoSubdomains, flags.NoExternals, flags.WithAssets, flags.Headers)
// Prepare output file
var file *os.File
if len(flags.Output) > 0 {
file = cli.PrepareOutputFile(flags.Output)
defer file.Close()
}
s := store.NewStore(file, flags.Quiet)
defer showStats(s, startTime)
// First scrap to get initial input
runInitScrap(c, s)
if flags.NoRecursion {
return
}
workers.RunCrawlerWorkers(c, s, flags.Threads, flags.Rate)
}
func main() {
cli.InitCli(start)
}