-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathxpath_test.go
More file actions
51 lines (48 loc) · 1.27 KB
/
Copy pathxpath_test.go
File metadata and controls
51 lines (48 loc) · 1.27 KB
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
44
45
46
47
48
49
50
51
package service
import (
"context"
"fmt"
"github.com/Jeffail/gabs/v2"
"github.com/JohnnyTing/rabida/config"
"github.com/chromedp/chromedp"
"github.com/sirupsen/logrus"
"testing"
)
func TestRabidaXpathImpl_Crawl(t *testing.T) {
conf := config.LoadFromEnv()
fmt.Printf("%+v\n", conf)
rabi := NewRabida(conf)
job := Job{
Link: "https://you.ctrip.com/sight/shenzhen26/2778.html",
CssSelector: CssSelector{
XpathScope: `//*[@id="commentModule"]/div[@class='commentList']/div`,
Attrs: map[string]CssSelector{
"content": {
Xpath: "//div[@class='commentDetail']",
},
"date": {
Xpath: `//div[@class='commentTime']`,
},
},
},
Paginator: CssSelector{
Xpath: "//*[@id='commentModule']//li[@class=' ant-pagination-next' and not(@aria-disabled='true')]",
},
Limit: 3,
}
err := rabi.Crawl(context.Background(), job, func(ret []interface{}, nextPageUrl string, currentPageNo int) bool {
for _, item := range ret {
fmt.Println(gabs.Wrap(item).StringIndent("", " "))
}
logrus.Printf("currentPageNo: %d\n", currentPageNo)
if currentPageNo >= job.Limit {
return true
}
return false
}, nil, []chromedp.Action{
chromedp.EmulateViewport(1777, 903, chromedp.EmulateLandscape),
})
if err != nil {
t.Error(fmt.Sprintf("%+v", err))
}
}