Merge pull request #18 from sundowndev/feat/gsearch

Add missing dorks in google search
pull/21/head
Raphaël 2020-09-12 19:04:25 +02:00 committed by GitHub
commit ba5b2e3aec
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 98 additions and 12 deletions

View File

@ -6,18 +6,24 @@ import (
)
const (
searchURL = "https://www.google.com/search"
siteTag = "site:"
urlTag = "inurl:"
filetypeTag = "filetype:"
cacheTag = "cache:"
relatedTag = "related:"
extTag = "ext:"
excludeTag = "-"
intitleTag = "intitle:"
intextTag = "intext:"
operatorOr = "|"
operatorAnd = "+"
searchURL = "https://www.google.com/search"
siteTag = "site:"
urlTag = "inurl:"
filetypeTag = "filetype:"
cacheTag = "cache:"
relatedTag = "related:"
extTag = "ext:"
excludeTag = "-"
intitleTag = "intitle:"
intextTag = "intext:"
operatorOr = "|"
operatorAnd = "+"
bookTag = "book:"
ipTag = "ip:"
mapsTag = "maps:"
allintextTag = "allintext:"
infoTag = "info:"
inanchorTag = "inanchor:"
)
// GoogleSearch is the Google search implementation for Dorkgen
@ -139,3 +145,33 @@ func (e *GoogleSearch) Plain(value string) *GoogleSearch {
e.tags = append(e.tags, value)
return e
}
// Book searches for book titles related to keywords.
func (e *GoogleSearch) Book(keyword string) *GoogleSearch {
e.tags = append(e.tags, e.join(bookTag, keyword, true))
return e
}
// Maps searches for maps related to keywords.
func (e *GoogleSearch) Maps(location string) *GoogleSearch {
e.tags = append(e.tags, e.join(mapsTag, location, false))
return e
}
// AllInText searches text of page.
func (e *GoogleSearch) AllInText(text string) *GoogleSearch {
e.tags = append(e.tags, e.join(allintextTag, text, true))
return e
}
// Info presents some information that Google has about a web page, including similar pages, the cached version of the page, and sites linking to the page.
func (e *GoogleSearch) Info(url string) *GoogleSearch {
e.tags = append(e.tags, e.join(infoTag, url, true))
return e
}
// InAnchor search link anchor text.
func (e *GoogleSearch) InAnchor(text string) *GoogleSearch {
e.tags = append(e.tags, e.join(inanchorTag, text, true))
return e
}

View File

@ -175,4 +175,54 @@ func TestInit(t *testing.T) {
"q": []string{"site:linkedin.com (intext:\"1\" | intext:\"2\") intitle:\"jordan\""},
}, result, "they should be equal")
})
t.Run("should use book tag", func(t *testing.T) {
dork = googlesearch.New()
result := dork.
Book("test").
String()
assert.Equal("book:\"test\"", result, "they should be equal")
})
t.Run("should use maps tag", func(t *testing.T) {
dork = googlesearch.New()
result := dork.
Maps("france").
String()
assert.Equal("maps:france", result, "they should be equal")
})
t.Run("should use allintext tag", func(t *testing.T) {
dork = googlesearch.New()
result := dork.
AllInText("test").
String()
assert.Equal("allintext:\"test\"", result, "they should be equal")
})
t.Run("should use info tag", func(t *testing.T) {
dork = googlesearch.New()
result := dork.
Info("https://google.com/").
String()
assert.Equal("info:\"https://google.com/\"", result, "they should be equal")
})
t.Run("should use inanchor tag", func(t *testing.T) {
dork = googlesearch.New()
result := dork.
InAnchor("test").
String()
assert.Equal("inanchor:\"test\"", result, "they should be equal")
})
}