getPageCount fixed

This commit is contained in:
milarin 2023-03-06 11:49:13 +01:00
parent 391e6f7295
commit bbb28298f8

14
api.go
View File

@ -175,9 +175,9 @@ func (api *Api) GetChapterEntriesByNovelID(novelID NovelID) *Cursor[NovelChapter
func (api *Api) getPageCount(doc *goquery.Document) (int, error) { func (api *Api) getPageCount(doc *goquery.Document) (int, error) {
pagination := doc.Find(".digg_pagination") pagination := doc.Find(".digg_pagination")
if pagination.Children().Length() >= 6 { if pagination.Length() > 0 {
// more than 4 pages (next_page + last_page + collapsed_pages buttons included) // more than 1 page
pageCount, err := strconv.ParseInt(pagination.Find("a:nth-child(5)").Text(), 10, 64) pageCount, err := strconv.ParseInt(pagination.Find("a:nth-last-child(2)").Text(), 10, 64)
if err != nil { if err != nil {
adverr.Println(ErrApiElementNotFound.Wrap(err, ".digg_pagination a:nth-child(5)")) adverr.Println(ErrApiElementNotFound.Wrap(err, ".digg_pagination a:nth-child(5)"))
return 0, err return 0, err
@ -185,13 +185,7 @@ func (api *Api) getPageCount(doc *goquery.Document) (int, error) {
return int(pageCount), nil return int(pageCount), nil
} else { } else {
pageCount, err := strconv.ParseInt(pagination.Find(".next_page").Text(), 10, 64) return 1, nil
if err != nil {
adverr.Println(ErrApiElementNotFound.Wrap(err, ".digg_pagination a:nth-child(5)"))
return 0, err
}
return int(pageCount), nil
} }
} }