Skip to content
This repository has been archived by the owner on Sep 21, 2021. It is now read-only.

Commit

Permalink
fix(spider): subject.score_details won't be empty string (#34)
Browse files Browse the repository at this point in the history
  • Loading branch information
trim21 committed Mar 22, 2020
1 parent 78cfa16 commit 4b72170
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
1 change: 1 addition & 0 deletions pkg/spider/background.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ func parser(resQueue chan response) {
subject.Image = getImageURL(doc)
subject.Score = getScore(doc)
subject.Info = getInfo(doc)
subject.ScoreDetails = getScoreDetails(doc)
subject.SubjectType = getSubjectType(doc)
uploadSubject(&subject)
}()
Expand Down
14 changes: 14 additions & 0 deletions pkg/spider/subject.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,20 @@ func getCollectorCount(doc *html.Node, subject *db.Subject) {
}
}

func getScoreDetails(doc *html.Node) string {
var detail = make(map[string]string)
detail["total"] = htmlquery.InnerText(htmlquery.FindOne(doc, `//*[@id="ChartWarpper"]/div/small/span/text()`))
for _, li := range htmlquery.Find(doc, `//*[@id="ChartWarpper"]/ul[@class="horizontalChart"]/li`) {
s := htmlquery.InnerText(htmlquery.FindOne(doc, `.//span[@class="count"]/text()`))
detail[htmlquery.InnerText(htmlquery.FindOne(li, `.//span[@class="label"]/text()`))] = s[1 : len(s)-1]
}
data, err := json.Marshal(detail)
if err != nil {
return "{}"
}
return string(data)
}

func getInfo(doc *html.Node) string {
var info = make(map[string][]string)

Expand Down

0 comments on commit 4b72170

Please sign in to comment.