-
Notifications
You must be signed in to change notification settings - Fork 0
/
weblio.go
executable file
·37 lines (31 loc) · 991 Bytes
/
weblio.go
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
package main
import (
"fmt"
"log"
"unicode/utf8"
"github.com/PuerkitoBio/goquery"
"gopkg.in/alecthomas/kingpin.v2"
)
var (
word = kingpin.Arg("word", "target word").Required().String()
)
func main() {
kingpin.Parse()
doc, err := goquery.NewDocument("http://ejje.weblio.jp/content/" + *word)
if err != nil {
log.Fatal(err)
}
if isIncludeMultibyte(*word) {
fmt.Printf("日単語 : %s\n", *word)
fmt.Printf("英単語 : %s\n", doc.Find(".content-explanation").Text())
} else {
fmt.Printf("単語 : %s\n", *word)
fmt.Printf("主な意味 : %s\n", doc.Find(".content-explanation").Text())
fmt.Printf("音節 : %s\n", doc.Find(".syllableEjje").Text())
fmt.Printf("発音記号・読み方 : %s\n", doc.Find(".phoneticEjjeDesc").Text())
fmt.Printf("変形一覧 : %s\n", doc.Find(".conjugateRowR").Text())
}
}
func isIncludeMultibyte(str string) bool {
return utf8.RuneCountInString(str) != len(str)
}