fix(hianime-provider): use a more specific css selector

This commit is contained in:
Benexl
2025-08-12 12:31:03 +03:00
parent 8b123cdae2
commit 114fba27fd

View File

@@ -8,7 +8,11 @@ from ....provider.anime.types import (
SearchResult, SearchResult,
SearchResults, SearchResults,
) )
from ....provider.scraping.html_parser import extract_attributes, get_element_by_class from ....provider.scraping.html_parser import (
extract_attributes,
get_element_by_class,
get_elements_by_class,
)
def _parse_episodes(element_html: str) -> AnimeEpisodes: def _parse_episodes(element_html: str) -> AnimeEpisodes:
@@ -73,13 +77,23 @@ def map_to_search_results(
# Parse pagination to determine total pages # Parse pagination to determine total pages
total_pages = 1 total_pages = 1
pagination_last = get_element_by_class('page-item a[title="Last"]', full_html) # Use a simpler selector that is less prone to parsing issues.
if pagination_last: pagination_elements = get_elements_by_class("page-item", full_html)
attrs = extract_attributes(pagination_last) if pagination_elements:
href = attrs.get("href", "") # Find the last page number from all pagination links
if "?page=" in href: last_page_num = 0
total_pages = int(href.split("?page=")[-1]) for el in pagination_elements:
attrs = extract_attributes(el)
href = attrs.get("href", "")
if "?page=" in href:
try:
num = int(href.split("?page=")[-1])
if num > last_page_num:
last_page_num = num
except (ValueError, IndexError):
continue
if last_page_num > 0:
total_pages = last_page_num
page_info = PageInfo(total=total_pages) page_info = PageInfo(total=total_pages)
return SearchResults(page_info=page_info, results=results) return SearchResults(page_info=page_info, results=results)