Browse Source

no message

chenyuanyang 6 years ago
parent
commit
f8dd9d2bf3
3 changed files with 49 additions and 56 deletions
  1. 48
    0
      cmd/job/job.go
  2. 0
    55
      cmd/job/test.go
  3. 1
    1
      main.go

+ 48
- 0
cmd/job/job.go View File

@@ -9,6 +9,7 @@ import (
9 9
 	"github.com/jinzhu/gorm"
10 10
 	_ "github.com/go-sql-driver/mysql"
11 11
 	"github.com/spf13/cobra"
12
+	"github.com/gocolly/colly"
12 13
 	"net/url"
13 14
 	"strconv"
14 15
 	"strings"
@@ -126,3 +127,50 @@ func SyncTtsOss(text string, speed float64, pitch float64) (bool, string) {
126 127
 
127 128
 	return true, ""
128 129
 }
130
+
131
+func test() {
132
+
133
+	// Instantiate default collector
134
+	c := colly.NewCollector(
135
+		// Visit only domains: hackerspaces.org, wiki.hackerspaces.org
136
+		colly.AllowedDomains("dict.cn", "m.dict.cn"),
137
+	)
138
+
139
+	// On every a element which has href attribute call callback
140
+	c.OnHTML("div[class=sent]", func(e *colly.HTMLElement) {
141
+		//link := e.Attr("href")
142
+		// Print link
143
+		fmt.Printf("Link found: %q -> %s\n", e.Text)
144
+		// Visit link found on page
145
+		// Only those links are visited which are in AllowedDomains
146
+		//c.Visit(e.Request.AbsoluteURL(link))
147
+	})
148
+
149
+	/**
150
+	1. div[class=sent]
151
+	2. 例句 div[class=layout sort]
152
+	3. 词法用法 div[class=section learn]
153
+	4.
154
+	 */
155
+
156
+	// Before making a request print "Visiting ..."
157
+	c.OnRequest(func(r *colly.Request) {
158
+		fmt.Println("Visiting", r.URL.String())
159
+	})
160
+
161
+	// Start scraping on https://hackerspaces.org
162
+	c.Visit("http://dict.cn/about")
163
+}
164
+
165
+func newTestCmd() *cobra.Command {
166
+	cmd := &cobra.Command{
167
+		Use:   "test",
168
+		Short: "Run the test service",
169
+		Run: func(cmd *cobra.Command, args []string) {
170
+			//fmt.Println("Echo: " + strings.Join(args, " "))
171
+
172
+			test()
173
+		},
174
+	}
175
+	return cmd
176
+}

+ 0
- 55
cmd/job/test.go View File

@@ -1,56 +1 @@
1 1
 package job
2
-
3
-import (
4
-	"fmt"
5
-	_ "github.com/go-sql-driver/mysql"
6
-	"github.com/spf13/cobra"
7
-	"github.com/gocolly/colly"
8
-)
9
-
10
-func test() {
11
-
12
-	// Instantiate default collector
13
-	c := colly.NewCollector(
14
-		// Visit only domains: hackerspaces.org, wiki.hackerspaces.org
15
-		colly.AllowedDomains("dict.cn", "m.dict.cn"),
16
-	)
17
-
18
-	// On every a element which has href attribute call callback
19
-	c.OnHTML("div[class=sent]", func(e *colly.HTMLElement) {
20
-		//link := e.Attr("href")
21
-		// Print link
22
-		fmt.Printf("Link found: %q -> %s\n", e.Text)
23
-		// Visit link found on page
24
-		// Only those links are visited which are in AllowedDomains
25
-		//c.Visit(e.Request.AbsoluteURL(link))
26
-	})
27
-
28
-	/**
29
-	1. div[class=sent]
30
-	2. 例句 div[class=layout sort]
31
-	3. 词法用法 div[class=section learn]
32
-	4.
33
-	 */
34
-
35
-	// Before making a request print "Visiting ..."
36
-	c.OnRequest(func(r *colly.Request) {
37
-		fmt.Println("Visiting", r.URL.String())
38
-	})
39
-
40
-	// Start scraping on https://hackerspaces.org
41
-	c.Visit("http://dict.cn/about")
42
-}
43
-
44
-func newTestCmd() *cobra.Command {
45
-	cmd := &cobra.Command{
46
-		Use:   "test",
47
-		Short: "Run the test service",
48
-		Run: func(cmd *cobra.Command, args []string) {
49
-			//fmt.Println("Echo: " + strings.Join(args, " "))
50
-
51
-			test()
52
-		},
53
-	}
54
-	return cmd
55
-}
56
-

+ 1
- 1
main.go View File

@@ -29,7 +29,7 @@ func main() {
29 29
 	rootCmd.AddCommand(http.RunCommand())
30 30
 	rootCmd.AddCommand(version.RunCommand(apiVersion, gitCommit, built))
31 31
 	rootCmd.AddCommand(job.RunCommand())
32
-	rootCmd.AddCommand(test.newTestCmd())
32
+	rootCmd.AddCommand(job.newTestCmd())
33 33
 
34 34
 	if err := rootCmd.Execute(); err != nil {
35 35
 		panic(err)