Skip to content

Commit

Permalink
五一快乐,隔离一时爽,一直隔离一直爽
Browse files Browse the repository at this point in the history
  • Loading branch information
QuinnDK committed May 2, 2020
1 parent 8523b7c commit e2b9f78
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 7 deletions.
4 changes: 2 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import (

func main() {
engine.Run(engine.Request{
Url: "https://book.douban.com/subject/34907964/",
ParseFunc: parse.ParseBookDetail,
Url: "https://book.douban.com",
ParseFunc: parse.ParseTag,
})

//result, _ := fetcher.Fetch("https://book.douban.com")
Expand Down
2 changes: 1 addition & 1 deletion model/bookdetails.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,5 @@ type Bookdetail struct {
}

func (b Bookdetail) String() string {
return "书名: " + b.Title + " 作者: " + b.Author + " 出版社:" + b.Public + " 页数: " + strconv.Itoa(b.Booktages) + " 价格: " + b.Price + " 评分:" + b.Score + " 内容简介:" + b.Into
return "书名: " + b.Title + " 作者: " + b.Author + " 出版社:" + b.Public + " 页数: " + strconv.Itoa(b.Booktages) + " 价格: " + b.Price + " 评分:" + b.Score + " \n内容简介:" + b.Into
}
8 changes: 6 additions & 2 deletions parse/booklist.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,14 @@ func ParseBookList(contents []byte) engine.ParseResult {
result := engine.ParseResult{}

for _, m := range matches {

bookname := string(m[2])
result.Items = append(result.Items, string(m[2]))
result.Requesrts = append(result.Requesrts, engine.Request{
Url: string(m[1]),
ParseFunc: engine.NilParse,
Url: string(m[1]),
ParseFunc: func(c []byte) engine.ParseResult {
return ParseBookDetail(c, bookname)
},
})

}
Expand Down
2 changes: 1 addition & 1 deletion parse/parsebookdetail.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ 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 {
func ParseBookDetail(contents []byte, bookname string) engine.ParseResult {

bookedetail := model.Bookdetail{}

Expand Down
2 changes: 1 addition & 1 deletion parse/parsetag.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ func ParseTag(content []byte) engine.ParseResult {
result.Items = append(result.Items, m[2])
result.Requesrts = append(result.Requesrts, engine.Request{
Url: "https://book.douban.com" + string(m[1]),
ParseFunc: engine.NilParse,
ParseFunc: ParseBookList,
})
}

Expand Down

0 comments on commit e2b9f78

Please sign in to comment.