-
Notifications
You must be signed in to change notification settings - Fork 0
/
search.go
54 lines (41 loc) · 1.56 KB
/
search.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
package main
import (
"fmt"
"strings"
"github.com/gocolly/colly/v2"
)
func search() []item {
var hits []item
c := colly.NewCollector()
c.OnHTML("table.memberdecls a.el", func(e *colly.HTMLElement) {
link := e.Attr("href")
if !(strings.HasPrefix(link, "group__") && strings.HasSuffix(link, ".html")) {
return
}
fmt.Printf("%s\n%s\n", e.Text, strings.Repeat("-", len(e.Text)))
c.Visit(e.Request.AbsoluteURL(link))
fmt.Println()
})
c.OnHTML("table.memberdecls", func(e *colly.HTMLElement) {
tableTitle := e.ChildText("tbody > .heading h2")
if tableTitle != "Functions" { return }
e.ForEach("tr", func(_ int, el *colly.HTMLElement) {
cname := el.Attr("class")
if strings.HasPrefix(cname, "separator") || cname == "Heading" {
return
} else if strings.HasPrefix(cname, "memitem") {
hits = append(hits,
item{
Titl: fmt.Sprintf("%s %s", el.ChildText(".memItemLeft"), el.ChildText(".memItemRight")),
Desc: "",
URL: fmt.Sprintf("%s%s", "https://llvm.org/doxygen/", el.ChildAttr(".memItemRight > a.el", "href"))})
fmt.Println(hits[len(hits)-1])
} else if strings.HasPrefix(cname, "memdesc") {
hits[len(hits)-1].Desc = el.ChildText(".mdescRight")
fmt.Println(hits[len(hits)-1])
}
})
})
c.Visit("https://llvm.org/doxygen/group__LLVMC.html")
return hits
}