Skip to content

Commit

Permalink
Show word's part of speech
Browse files Browse the repository at this point in the history
Deal with situations that the query word does not return part of speech
  • Loading branch information
xwjdsh committed Mar 13, 2018
1 parent ec4aa7c commit ed5e73f
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions query.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,17 @@ func query(words []string, withVoice, withMore, isMulti bool) {
if isChinese {
// Find the result
fmt.Println()
doc.Find(".trans-container > ul > p > span.contentTitle").Each(func(i int, s *goquery.Selection) {
color.Green(" %s", s.Find(".search-js").Text())
doc.Find(".trans-container > ul > p").Each(func(i int, s *goquery.Selection) {
partOfSpeech := s.Children().Not(".contentTitle").Text()
if partOfSpeech != "" {
fmt.Printf("%14s ", color.MagentaString(partOfSpeech))
}

meanings := []string{}
s.Find(".contentTitle > .search-js").Each(func(ii int, ss *goquery.Selection) {
meanings = append(meanings, ss.Text())
})
fmt.Printf("%s\n", color.GreenString(strings.Join(meanings, "; ")))
})
} else {

Expand Down

0 comments on commit ed5e73f

Please sign in to comment.