Prva verzija - klix scraper

This commit is contained in:
Senad Uka
2022-02-10 21:11:13 +01:00
parent 08f0de07c3
commit a040320827
13 changed files with 348 additions and 0 deletions

View File

@@ -0,0 +1,26 @@
package scraper
import (
"github.com/PuerkitoBio/goquery"
)
func extractJustText(el *goquery.Selection) string {
textPart := ""
htmlPart, _ := el.Html()
if len(el.Nodes) == 0 {
return ""
}
//fmt.Println("Checking: ", htmlPart, "Duzina: ", strconv.Itoa(len(el.Nodes)), " Type je ", el.Nodes[0].Type, " jednakost ", el.Text() == htmlPart)
if len(el.Nodes) == 1 && el.Text() == htmlPart {
return el.Text() + "\n"
}
el.Children().Each(func(_ int, el2 *goquery.Selection) {
if el2.Is("div, p, span, a") {
textPart += extractJustText(el2)
}
})
return textPart
}