-
Notifications
You must be signed in to change notification settings - Fork 0
/
tagfuncs.go
46 lines (34 loc) · 914 Bytes
/
tagfuncs.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
package sitescraper
import "strings"
//Returns InnerHTML inside a Tag as string
func (t Tag) GetInnerHTML() string {
return t.innerHTML
}
//Returns pure Text inside a Tag
func (t Tag) GetText() string {
return getText(t.tagname, t.innerHTML)
}
//Returns the name of the Tag as string
func (t Tag) GetTagName() string {
return t.tagname
}
//Returns the Value of the given Attribute as string
func (t Tag) GetAttrValue(attr string) string {
var out string
if strings.Contains(t.tagcontent, attr+"=") {
out = t.tagcontent[strings.Index(t.tagcontent, attr+`=`)+len(attr+`=`):]
}
if strings.Contains(out, ">") {
out = strings.ReplaceAll(out, ">", "")
}
if strings.Contains(out, `"`) {
out = strings.ReplaceAll(out, `"`, "")
}
if strings.Contains(out, " ") {
out = out[:strings.Index(out, " ")]
}
if strings.Contains(out, `'`) {
out = strings.ReplaceAll(out, `'`, "")
}
return out
}