File tree Expand file tree Collapse file tree 2 files changed +14
-4
lines changed Expand file tree Collapse file tree 2 files changed +14
-4
lines changed Original file line number Diff line number Diff line change 11pkg
22src
3+ crawler_cache
Original file line number Diff line number Diff line change @@ -24,6 +24,7 @@ func onRequest(r *colly.Request) {
2424
2525func 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 )
You can’t perform that action at this time.
0 commit comments