Skip to content

Commit 89c2441

Browse files
committed
extend links range
1 parent bf1f558 commit 89c2441

2 files changed

Lines changed: 17 additions & 8 deletions

File tree

internal/fetcher/links.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,11 @@ func (f *Fetcher) SetLinks() error {
3535
f.Links = LinksFilter(links, `.*?/.*?-\d*.html`)
3636
KickOutLinksMatchPath(&f.Links, "about")
3737
case "www.zaobao.com":
38-
f.Links = LinksFilter(links, `.*?/world/.*`)
38+
newsWorld := LinksFilter(links, `.*?/news/world/.*`)
39+
newsChina := LinksFilter(links, `.*?/news/china/.*`)
40+
realtimeWorld := LinksFilter(links, `.*?/realtime/world/.*`)
41+
realtimeChina := LinksFilter(links, `.*?/realtime/china/.*`)
42+
f.Links = append(append(append(newsWorld, newsChina...), realtimeWorld...), realtimeChina...)
3943
}
4044
return nil
4145
}

internal/fetcher/links_test.go

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package fetcher
22

33
import (
4-
"fmt"
54
"net/url"
65
"testing"
76
)
@@ -18,23 +17,29 @@ func TestKickOutLinksMatchPath(t *testing.T) {
1817
}
1918

2019
func TestSetLinks(t *testing.T) {
21-
u, err := url.Parse("https://www.zaobao.com/realtime/world")
20+
u, err := url.Parse("https://www.zaobao.com/realtime/")
2221
if err != nil {
2322
t.Errorf("Url Parse fail!\n%s", err)
2423
}
2524
var f = &Fetcher{
2625
Entrance: u,
2726
}
2827
f.SetLinks()
29-
assertLink := "https://www.zaobao.com/realtime/world/story20200825-1079575"
28+
assertLinks := []string{
29+
"https://www.zaobao.com/realtime/china/story20200825-1079597",
30+
"https://www.zaobao.com/realtime/world/story20200825-1079575",
31+
"https://www.zaobao.com/news/china/story20200825-1079462",
32+
"https://www.zaobao.com/news/world/story20200825-1079476",
33+
}
3034
shot := 0
3135
for _, link := range f.Links {
32-
fmt.Println(link)
33-
if link == assertLink {
34-
shot++
36+
for _, v := range assertLinks {
37+
if link == v {
38+
shot++
39+
}
3540
}
3641
}
3742
if shot == 0 {
38-
t.Errorf("want: %v, got: %v", 1, shot)
43+
t.Errorf("want: %v, got: %v", len(assertLinks), shot)
3944
}
4045
}

0 commit comments

Comments
 (0)