"""XHamster.com, direct HTML scrape search results. Search: `https://xhamster.com/search/?page=` Scene URL: `https://xhamster.com/videos/-` """ from __future__ import annotations import re # Karty sa renderowane z JSON-a w HTML (`window.initials`): kazda ma `pageURL` i # `thumbURL` (526x298 webp). Szukanie `` w oknie tekstu gubilo polowe scen, bo # ten sam link wystepuje dwa razy (miniatura i tytul), a img jest tylko przy pierwszym. _JSON_CARD_RE = re.compile( r'"pageURL":"(https:\\/\\/xhamster\.com\\/videos\\/[^"]+)","thumbURL":"([^"]+)"' ) from app.connectors.direct_scrapers._search_base import BaseSearchScraper class XHamsterScraper(BaseSearchScraper): sitetag = "xhamstercom" _search_url_template = "https://xhamster.com/search/{query}?page={page}" _scene_url_re = re.compile( r'href="(?Phttps://xhamster\.com/videos/(?P[a-z0-9_\-]+))"', re.IGNORECASE, ) def _thumbnail_map(self, listing_html: str) -> dict[str, str]: out: dict[str, str] = {} for page_url, thumb in _JSON_CARD_RE.findall(listing_html): out[page_url.replace("\\/", "/")] = thumb.replace("\\/", "/") return out