Skip to content

Commit

Permalink
五一快乐,隔离一时爽,一直隔离一直爽
Browse files Browse the repository at this point in the history
  • Loading branch information
QuinnDK committed May 1, 2020
1 parent 46598a1 commit 8523b7c
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
7 changes: 7 additions & 0 deletions model/bookdetails.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,17 @@
package model

import "strconv"

type Bookdetail struct {
Title string
Author string
Public string
Booktages int
Price string
Score string
Into string
}

func (b Bookdetail) String() string {
return "书名: " + b.Title + " 作者: " + b.Author + " 出版社:" + b.Public + " 页数: " + strconv.Itoa(b.Booktages) + " 价格: " + b.Price + " 评分:" + b.Score + " 内容简介:" + b.Into
}
8 changes: 5 additions & 3 deletions parse/parsebookdetail.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,19 @@ import (
"strconv"
)

var title = regexp.MustCompile(`<span property="v:itemreviewed">([^<]+)</span>`)
var autoRe = regexp.MustCompile(`<span class="pl"> 作者</span>:[\d\D]*?<a.*?>([^<]+)</a>`)
var publuc = regexp.MustCompile(`<span class="pl">出版社:</span>([^<]+)<br>`)
var pageRe = regexp.MustCompile(`<span class="pl">页数:</span> ([^<]+)<br>`)
var priceRe = regexp.MustCompile(`<span class="pl">定价:</span> ([^<]+ )<br>`)
var publuc = regexp.MustCompile(`<span class="pl">出版社:</span>([^<]+)<br/>`)
var pageRe = regexp.MustCompile(`<span class="pl">页数:</span> ([^<]+)<br/>`)
var priceRe = regexp.MustCompile(`<span class="pl">定价:</span> ([^<]+)<br/>`)
var scoreRe = regexp.MustCompile(`<strong class="ll rating_num " property="v:average">([^<]+ )</strong>`)
var intoRe = regexp.MustCompile(`<div class="intro">[\d\D]*?<p>([^<]+)</p>[\d\D]*?<p>([^<]+)</p></div>`)

func ParseBookDetail(contents []byte) engine.ParseResult {

bookedetail := model.Bookdetail{}

bookedetail.Title = ExtraString(contents, title)
bookedetail.Author = ExtraString(contents, autoRe)
bookedetail.Public = ExtraString(contents, publuc)
page, err := strconv.Atoi(ExtraString(contents, pageRe))
Expand Down

0 comments on commit 8523b7c

Please sign in to comment.