soimort/you-get · error · AssertionError

not found total count in html

Error message

not found total count in html

What it means

After fetching the lrts.me book page, the extractor scrapes the total chapter count via the literal pattern r"var totalCount='(\d+)'" from the raw HTML. If the markup no longer embeds that JavaScript variable, it raises AssertionError('not found total count in html') — the extractor cannot compute pagination (last_page = total_count // page_size + 1) without it.

Source

Thrown at src/you_get/extractors/lrts.py:24

from ..common import *
from ..util import log, term

def lrts_download(url, output_dir='.', merge=True, info_only=False, **kwargs):
    html = get_html(url)
    args = kwargs.get('args')
    if not args: args = {}
    matched = re.search(r"/book/(\d+)", url)
    if not matched:
        raise AssertionError("not found book number: %s" % url)
    book_no = matched.group(1)
    book_title = book_no
    matched = re.search(r"<title>([^-]*)[-](.*)[,](.*)</title>", html)
    if matched:
        book_title = matched.group(1)

    matched = re.search(r"var totalCount='(\d+)'", html)
    if not matched:
        raise AssertionError("not found total count in html")
    total_count = int(matched.group(1))
    log.i('%s total: %s' % (book_title, total_count))
    first_page = 0
    if ('first' in args and args.first!= None):
        first_page = int(args.first)

    page_size = 10
    if ('page_size' in args and args.page_size != None):
        page_size = int(args.page_size)
    last_page = (total_count // page_size) + 1
    if ('last' in args and args.last != None):
        last_page = int(args.last)

    log.i('page size is %s, page from %s to %s' % (page_size, first_page, last_page))
    headers = {
      'Referer': url
    }
    items = []

View on GitHub (pinned to 049548f3f3)

Solutions

  1. Print/inspect the HTML returned by get_html(url) — confirm you got the real book page and not a block/login page
  2. Locate the new home of the total count in the page source (search for 'totalCount' or the chapter count) and update the regex at src/you_get/extractors/lrts.py:24
  3. If the value moved to an AJAX endpoint, fetch that endpoint instead of scraping HTML
  4. Pass explicit --first/--last page args once pagination is understood, so the count scrape can be bypassed

Example fix

# before
matched = re.search(r"var totalCount='(\d+)'", html)
if not matched:
    raise AssertionError("not found total count in html")

# after (tolerate double quotes and JSON style)
matched = re.search(r"totalCount['\"]?\s*[:=]\s*['\"]?(\d+)", html)
if not matched:
    raise AssertionError("not found total count in html")
Defensive patterns

Strategy: validation

Validate before calling

import re

def lrts_page_has_count(html):
    return re.search(r"var totalCount='(\d+)'", html) is not None

Try / catch

try:
    lrts_download(url, ...)
except AssertionError as e:
    if 'total count' in str(e):
        print('page layout changed or a block page was served; inspect HTML')
    else:
        raise

Prevention

When it happens

Trigger: The fetched HTML is not the expected book page: a login/region/captcha interstitial, a 200-status error page, or a site redesign that renamed or reformatted the totalCount variable (quotes, spacing, JSON-ification).

Common situations: Site frontend rewrite moving the value into a JSON blob or script bundle; being geo-blocked or rate-limited so get_html returns an error shell; the book being removed so the page renders without chapter data.

Related errors


AI-assisted analysis of soimort/you-get@049548f3f3 (2026-08-15). Data as JSON: /api/errors/12246e5647f48ae3. Report an issue: GitHub.