31 lines
733 B
Go
31 lines
733 B
Go
package parser
|
|
|
|
import (
|
|
"io"
|
|
|
|
"github.com/PuerkitoBio/goquery"
|
|
)
|
|
|
|
// ParseHtml parse html from reader
|
|
// @reader - reader instance
|
|
// @findRule - find rule (css-selector, z-index, etc...)
|
|
// @tag - html tag, which text has needed from @reader
|
|
func ParseHtml(reader io.Reader, findRule string, tag string) ([]string, error) {
|
|
// Load the HTML document
|
|
var result []string
|
|
doc, err := goquery.NewDocumentFromReader(reader)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
// Find the review items
|
|
doc.Find(findRule).Each(func(i int, s *goquery.Selection) {
|
|
// For each item found, get the text
|
|
text := s.Find(tag).Text()
|
|
// fmt.Printf("Найден: %d: %s\n", i+1, text)
|
|
result = append(result, text)
|
|
})
|
|
return result, err
|
|
|
|
}
|