Skip to content

Commit 4e6a7a6

Browse files
author
Jesus Olmos
committed
crawl optional cache
1 parent 5a4f186 commit 4e6a7a6

File tree

2 files changed

+14
-4
lines changed

2 files changed

+14
-4
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
pkg
22
src
3+
crawler_cache

crawl.go

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ func onRequest(r *colly.Request) {
2424

2525
func main() {
2626
url := flag.String("url", "", "url to crawl")
27+
cache := flag.Bool("cache", false, "enable cache")
2728
flag.Parse()
2829

2930
if *url == "" {
@@ -39,10 +40,18 @@ func main() {
3940

4041
dom := purl[2]
4142

42-
c := colly.NewCollector(
43-
colly.AllowedDomains(dom),
44-
colly.CacheDir("./crawler_cache"),
45-
)
43+
var c *colly.Collector
44+
45+
if *cache {
46+
c = colly.NewCollector(
47+
colly.AllowedDomains(dom),
48+
colly.CacheDir("./crawler_cache"),
49+
)
50+
} else {
51+
c = colly.NewCollector(
52+
colly.AllowedDomains(dom),
53+
)
54+
}
4655

4756
c.OnHTML("a[href]", onHtml)
4857
c.OnRequest(onRequest)

0 commit comments

Comments
 (0)