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