-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathparentSibling.go
43 lines (37 loc) · 1.83 KB
/
parentSibling.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
package webscraper
// Recursively traverses through parent elements of current element until
// it finds the element that satisfies tag and attrs
func (e Element) FindParent(tag string, attrs ...string) Element {
return e.findElement(getParent, tag, attrs)
}
// Recursively traverses through all parent elements of current element and
// returns []Element that contains elements that satisfies tag and attrs.
// If limit == -1, then there is no limit.
// If limit == n, it will return only n-number of elements
func (e Element) FindParents(tag string, limit int, attrs ...string) []Element {
return e.findElements(getParent, tag, limit, attrs)
}
// Traverses through sibling elements BEFORE current element,
// and returns element if it satisfies the searching parameters.
// Otherwise, returns nil
func (e Element) FindPrevSibling(tag string, attrs ...string) Element {
return e.findElement(getPrevSibling, tag, attrs)
}
// Traverses through sibling elements AFTER current element,
// and returns element if it satisfies the searching parameters.
// Otherwise, returns nil
func (e Element) FindNextSibling(tag string, attrs ...string) Element {
return e.findElement(getNextSibling, tag, attrs)
}
// Traverses through sibling elements BEFORE current element,
// and returns []Element that contains elements that satisfies the searching
// parameters. Otherwise, returns nil
func (e Element) FindPrevSiblings(tag string, limit int, attrs ...string) []Element {
return e.findElements(getPrevSibling, tag, limit, attrs)
}
// Traverses through sibling elements AFTER current element,
// and returns []Element that contains elements that satisfies the searching
// parameters. Otherwise, returns nil
func (e Element) FindNextSiblings(tag string, limit int, attrs ...string) []Element {
return e.findElements(getNextSibling, tag, limit, attrs)
}