Options used instead of direct parameter passing.

Tests updated.
This commit is contained in:
Musab Gültekin
2019-06-06 23:49:42 +03:00
parent 6358b87472
commit 944bd3bada
2 changed files with 28 additions and 25 deletions

View File

@ -2,25 +2,28 @@ package gezer
import (
"fmt"
"github.com/PuerkitoBio/goquery"
"testing"
)
func TestGezer_StartURLs_Simple(t *testing.T) {
gezer := NewGezer(parse, "https://api.ipify.org", "https://api.ipify.org")
gezer := NewGezer(Opt{
StartURLs: []string{"https://api.ipify.org", "https://api.ipify.org"},
ParseFunc: func(r *Response) {
fmt.Println(string(r.Body))
},
})
gezer.Start()
}
func parse(response *Response) {
fmt.Println(string(response.Body))
func TestGezer_StartURLs_HTML(t *testing.T) {
gezer := NewGezer(Opt{
StartURLs: []string{"http://quotes.toscrape.com/"},
ParseFunc: func(r *Response) {
r.Doc.Find("div.quote").Each(func(i int, s *goquery.Selection) {
fmt.Println(i, s.Find("span.text").Text(), s.Find("small.author").Text())
})
},
})
gezer.Start()
}
//func TestGezer_StartURLs_HTML(t *testing.T) {
// gezer := NewGezer(parse, "http://quotes.toscrape.com/")
// gezer.Start()
// for result := range gezer.Results {
// result.Doc.Find("div.quote").Each(func(_ int, s *goquery.Selection) {
// fmt.Println(s.Find("span.text").Text())
// fmt.Println(s.Find("small.author").Text())
// })
// }
//}