@@ -33,7 +33,6 @@ func run(crawl bool, silent bool) {
3333 // Create a new crolly collector
3434 c := colly .NewCollector (
3535 colly .MaxDepth (args .Depth ),
36- colly .Async (true ),
3736 )
3837
3938 // Parallelism can be controlled also by spawning fixed
@@ -78,45 +77,47 @@ func Crawl(c *colly.Collector, wg *sync.WaitGroup, url string, payload string, s
7877 c .OnHTML ("a[href]" , func (e * colly.HTMLElement ) {
7978 link := e .Attr ("href" )
8079 e .Request .Visit (e .Request .AbsoluteURL (link ))
81- match , _ := regexp .MatchString (args .Regex , link )
82- inScope , _ := regexp .MatchString (args .Scope , link )
80+ })
81+
82+ // The request of each link visisted
83+ c .OnRequest (func (r * colly.Request ) {
84+
85+ match , _ := regexp .MatchString (args .Regex , r .URL .String ())
86+ inScope , _ := regexp .MatchString (args .Scope , r .URL .String ())
8387
8488 if args .Regex != "" && args .Scope != "" && match && inScope {
8589
8690 if ! silent {
87- gologger .Debug ().Msg ("Crawled " + link )
91+ gologger .Debug ().Msg ("Crawled " + r . URL . String () )
8892 }
89- traversal .TestTraversal (wg , link , payload , silent )
93+ traversal .TestTraversal (wg , r . URL . String () , payload , silent )
9094
9195 } else {
9296 if args .Regex != "" {
9397 if match {
9498 if ! silent {
95- gologger .Debug ().Msg ("Crawled " + link )
99+ gologger .Debug ().Msg ("Crawled " + r . URL . String () )
96100 }
97- traversal .TestTraversal (wg , link , payload , silent )
101+ traversal .TestTraversal (wg , r . URL . String () , payload , silent )
98102 }
99103
100104 } else if args .Scope != "" {
101105 if inScope {
102106 if ! silent {
103- gologger .Debug ().Msg ("Crawled " + link )
107+ gologger .Debug ().Msg ("Crawled " + r . URL . String () )
104108 }
105- traversal .TestTraversal (wg , link , payload , silent )
109+ traversal .TestTraversal (wg , r . URL . String () , payload , silent )
106110 }
107111
108112 } else {
109113 if ! silent {
110- gologger .Debug ().Msg ("Crawled " + link )
114+ gologger .Debug ().Msg ("Crawled " + r . URL . String () )
111115 }
112- traversal .TestTraversal (wg , link , payload , silent )
113-
116+ traversal .TestTraversal (wg , r .URL .String (), payload , silent )
114117 }
115118
116119 }
117- })
118120
121+ })
119122 c .Visit (url )
120- // Wait until threads are finished
121- c .Wait ()
122123}
0 commit comments