mirror of
https://github.com/edoardottt/cariddi.git
synced 2026-09-29 21:14:58 +02:00
update
This commit is contained in:
+6
-5
@@ -2,18 +2,16 @@ package crawler
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"regexp"
|
||||
|
||||
"github.com/gocolly/colly"
|
||||
)
|
||||
|
||||
//Crawler
|
||||
func Crawler(target string) {
|
||||
func Crawler(target string) []string {
|
||||
var result []string
|
||||
// Instantiate default collector
|
||||
c := colly.NewCollector(
|
||||
colly.URLFilters(
|
||||
regexp.MustCompile(".*" + target + "*"),
|
||||
),
|
||||
colly.AllowedDomains(target),
|
||||
)
|
||||
|
||||
// On every a element which has href attribute call callback
|
||||
@@ -24,6 +22,7 @@ func Crawler(target string) {
|
||||
// Visit link found on page
|
||||
// Only those links are visited which are in AllowedDomains
|
||||
c.Visit(e.Request.AbsoluteURL(link))
|
||||
result = append(result, e.Request.AbsoluteURL(link))
|
||||
})
|
||||
|
||||
// Before making a request print "Visiting ..."
|
||||
@@ -33,4 +32,6 @@ func Crawler(target string) {
|
||||
|
||||
// Start scraping on target
|
||||
c.Visit("http://" + target)
|
||||
c.Visit("https://" + target)
|
||||
return result
|
||||
}
|
||||
|
||||
@@ -1,8 +1,6 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/edoardottt/cariddi/crawler"
|
||||
"github.com/edoardottt/cariddi/input"
|
||||
"github.com/edoardottt/cariddi/output"
|
||||
@@ -11,11 +9,14 @@ import (
|
||||
|
||||
//main
|
||||
func main() {
|
||||
fmt.Println("cariddi")
|
||||
input := input.ScanInput()
|
||||
var finalResult []string
|
||||
for _, inp := range input {
|
||||
crawler.Crawler(inp)
|
||||
var result []string
|
||||
result = crawler.Crawler(inp)
|
||||
finalResult = append(finalResult, result...)
|
||||
}
|
||||
output.Beautify()
|
||||
output.PrintOutput(finalResult)
|
||||
scanner.Scan()
|
||||
}
|
||||
|
||||
+5
-3
@@ -2,7 +2,9 @@ package output
|
||||
|
||||
import "fmt"
|
||||
|
||||
//Output
|
||||
func Output() {
|
||||
fmt.Println("output")
|
||||
//PrintOutput
|
||||
func PrintOutput(out []string) {
|
||||
for _, elem := range out {
|
||||
fmt.Println(elem)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
package utils
|
||||
|
||||
//removeDuplicateValues
|
||||
func removeDuplicateValues(intSlice []string) []string {
|
||||
keys := make(map[string]bool)
|
||||
list := []string{}
|
||||
for _, entry := range intSlice {
|
||||
if _, value := keys[entry]; !value {
|
||||
keys[entry] = true
|
||||
list = append(list, entry)
|
||||
}
|
||||
}
|
||||
return list
|
||||
}
|
||||
Reference in New Issue
Block a user