extended price search
This commit is contained in:
parent
392400bd44
commit
4b53a1d395
1 changed files with 30 additions and 17 deletions
|
|
@ -235,16 +235,32 @@ func (s *MandarakeParser) findNode(doc *html.Node, params price) *html.Node {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *MandarakeParser) findData(doc *html.Node, params price) []string {
|
func (s *MandarakeParser) findData(doc *html.Node, params price) []string {
|
||||||
if doc != nil {
|
if doc == nil {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
var (
|
var (
|
||||||
crawler func(*html.Node)
|
crawler func(*html.Node)
|
||||||
values []string
|
values []string
|
||||||
|
getText func(*html.Node) string
|
||||||
)
|
)
|
||||||
|
|
||||||
|
getText = func(n *html.Node) string {
|
||||||
|
if n.Type == html.TextNode {
|
||||||
|
return n.Data
|
||||||
|
}
|
||||||
|
var result strings.Builder
|
||||||
|
for c := n.FirstChild; c != nil; c = c.NextSibling {
|
||||||
|
result.WriteString(getText(c))
|
||||||
|
}
|
||||||
|
return result.String()
|
||||||
|
}
|
||||||
|
|
||||||
crawler = func(node *html.Node) {
|
crawler = func(node *html.Node) {
|
||||||
if node.Type == html.ElementNode && node.Data == params.subTag {
|
if node.Type == html.ElementNode && node.Data == params.subTag {
|
||||||
if strings.Contains(node.FirstChild.Data, params.substring) {
|
text := strings.TrimSpace(getText(node))
|
||||||
values = append(values, node.FirstChild.Data)
|
if strings.Contains(text, params.substring) {
|
||||||
|
values = append(values, text)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for child := node.FirstChild; child != nil; child = child.NextSibling {
|
for child := node.FirstChild; child != nil; child = child.NextSibling {
|
||||||
|
|
@ -252,10 +268,7 @@ func (s *MandarakeParser) findData(doc *html.Node, params price) []string {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
crawler(doc)
|
crawler(doc)
|
||||||
|
|
||||||
return values
|
return values
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *MandarakeParser) getPrice(rawStr []string) int {
|
func (s *MandarakeParser) getPrice(rawStr []string) int {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue