/
type.go
85 lines (64 loc) · 2.01 KB
/
type.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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
package scrapy
import(
"log"
"regexp"
"strings"
"github.com/leandrofroes/manw/pkg/utils"
"github.com/leandrofroes/manw/pkg/cache"
"github.com/gocolly/colly"
)
func parseMSDNDataType(search, url string) string{
var dataTypeInfo string
collector := colly.NewCollector(
colly.UserAgent("Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:47.0) Gecko/20100101 Firefox/47.0"),
)
collector.OnHTML("tr", func(e *colly.HTMLElement){
str := strings.ToUpper(search) + "\n"
re, err := regexp.Compile(str)
utils.CheckError(err)
match := re.FindString(e.Text)
index := strings.Index(e.Text, str)
if match != "" && index == 1{
strSlice := strings.Split(e.Text, "\n")
dataTypeInfo += "\nData Type: "
for i, str := range strSlice{
if i > 0 && i < len(strSlice) - 1{
dataTypeInfo += str + "\n\n"
}
}
}
})
collector.OnError(func(r *colly.Response, err error) {
log.Fatal(err)
})
collector.Visit(url)
return dataTypeInfo
}
func RunTypeScraper(search, cachePath string){
search = strings.ToLower(search)
if cachePath != ""{
if !cache.CheckCache(search, cachePath){
searchAux := "+windows+data+type+msdn"
url := GoogleMSDNSearch(search, searchAux)
if url == ""{
utils.Warning("Unable to find this Windows data type.")
}
dataTypeInfo := parseMSDNDataType(search, url)
if dataTypeInfo == ""{
utils.Warning("Unable to find this Windows data type.")
}
cache.RunTypeCache(search, dataTypeInfo, cachePath)
}
} else {
searchAux := "+windows+data+type+msdn"
url := GoogleMSDNSearch(search, searchAux)
if url == ""{
utils.Warning("Unable to find this Windows data type.")
}
dataTypeInfo := parseMSDNDataType(search, url)
if dataTypeInfo == ""{
utils.Warning("Unable to find this Windows data type.")
}
utils.GenericPrint(dataTypeInfo)
}
}