Module hdrezka.post.site.navbar
Top navigation bar parsing.
Functions
-
Expand source code
def parse_navbar(html: str | BeautifulSoup | Tag) -> Navbar: """ Parse ``ul#topnav-menu`` into a ``Navbar``. Returns an empty ``Navbar`` when the menu is missing. """ soup = as_soup(html) menu = soup.select_one('ul#topnav-menu.b-topnav__inner') or soup.select_one('ul#topnav-menu') if menu is None: return Navbar() items = [] for li in menu.find_all('li', class_='b-topnav__item', recursive=False): classes = li.get('class') or [] is_single = 'single' in classes link = li.select_one('a.b-topnav__item-link') if link is None: continue items.append(NavItem( name=text(link), url=attr(link, 'href', default='') or '', single=is_single, submenu=None if is_single else _parse_submenu(li), )) return Navbar(items=tuple(items))
Classes
-
Expand source code
class FindBestBlock(NamedTuple): """Category and year selectors from ``.b-topnav__findbest_block``.""" categories: tuple[FindBestOption, ...] = () years: tuple[FindBestOption, ...] = ()Category and year selectors from
.b-topnav__findbest_block.Ancestors
- builtins.tuple
Instance variables
-
Expand source code
class FindBestBlock(NamedTuple): """Category and year selectors from ``.b-topnav__findbest_block``.""" categories: tuple[FindBestOption, ...] = () years: tuple[FindBestOption, ...] = ()Alias for field number 0
-
Expand source code
class FindBestBlock(NamedTuple): """Category and year selectors from ``.b-topnav__findbest_block``.""" categories: tuple[FindBestOption, ...] = () years: tuple[FindBestOption, ...] = ()Alias for field number 1
-
Expand source code
class FindBestOption(NamedTuple): """Option from a navbar “best of” ``<select>``.""" name: str value: str selected: bool = FalseOption from a navbar “best of”
<select>.Ancestors
- builtins.tuple
Instance variables
-
Expand source code
class FindBestOption(NamedTuple): """Option from a navbar “best of” ``<select>``.""" name: str value: str selected: bool = FalseAlias for field number 0
-
Expand source code
class FindBestOption(NamedTuple): """Option from a navbar “best of” ``<select>``.""" name: str value: str selected: bool = FalseAlias for field number 2
-
Expand source code
class FindBestOption(NamedTuple): """Option from a navbar “best of” ``<select>``.""" name: str value: str selected: bool = FalseAlias for field number 1
-
Expand source code
class NavCollection(NamedTuple): """Collection / platform link from a category submenu (right column).""" name: str url: str classes: tuple[str, ...] = ()Collection / platform link from a category submenu (right column).
Ancestors
- builtins.tuple
Instance variables
-
Expand source code
class NavCollection(NamedTuple): """Collection / platform link from a category submenu (right column).""" name: str url: str classes: tuple[str, ...] = ()Alias for field number 2
-
Expand source code
class NavCollection(NamedTuple): """Collection / platform link from a category submenu (right column).""" name: str url: str classes: tuple[str, ...] = ()Alias for field number 0
-
Expand source code
class NavCollection(NamedTuple): """Collection / platform link from a category submenu (right column).""" name: str url: str classes: tuple[str, ...] = ()Alias for field number 1
-
Expand source code
class NavItem(NamedTuple): """Single top-nav entry (with or without submenu).""" name: str url: str single: bool = False submenu: NavSubmenu | None = NoneSingle top-nav entry (with or without submenu).
Ancestors
- builtins.tuple
Instance variables
-
Expand source code
class NavItem(NamedTuple): """Single top-nav entry (with or without submenu).""" name: str url: str single: bool = False submenu: NavSubmenu | None = NoneAlias for field number 0
-
Expand source code
class NavItem(NamedTuple): """Single top-nav entry (with or without submenu).""" name: str url: str single: bool = False submenu: NavSubmenu | None = NoneAlias for field number 2
-
Expand source code
class NavItem(NamedTuple): """Single top-nav entry (with or without submenu).""" name: str url: str single: bool = False submenu: NavSubmenu | None = NoneAlias for field number 3
-
Expand source code
class NavItem(NamedTuple): """Single top-nav entry (with or without submenu).""" name: str url: str single: bool = False submenu: NavSubmenu | None = NoneAlias for field number 1
-
Expand source code
class NavSubmenu(NamedTuple): """Dropdown content under a top-nav category.""" genres: tuple[Hyperlink, ...] = () collections: tuple[NavCollection, ...] = () find_best: FindBestBlock | None = NoneDropdown content under a top-nav category.
Ancestors
- builtins.tuple
Instance variables
-
Expand source code
class NavSubmenu(NamedTuple): """Dropdown content under a top-nav category.""" genres: tuple[Hyperlink, ...] = () collections: tuple[NavCollection, ...] = () find_best: FindBestBlock | None = NoneAlias for field number 1
-
Expand source code
class NavSubmenu(NamedTuple): """Dropdown content under a top-nav category.""" genres: tuple[Hyperlink, ...] = () collections: tuple[NavCollection, ...] = () find_best: FindBestBlock | None = NoneAlias for field number 2
-
Expand source code
class NavSubmenu(NamedTuple): """Dropdown content under a top-nav category.""" genres: tuple[Hyperlink, ...] = () collections: tuple[NavCollection, ...] = () find_best: FindBestBlock | None = NoneAlias for field number 0
-
Expand source code
class Navbar(NamedTuple): """Full site top navigation map.""" items: tuple[NavItem, ...] = ()Full site top navigation map.
Ancestors
- builtins.tuple
Instance variables
-
Expand source code
class Navbar(NamedTuple): """Full site top navigation map.""" items: tuple[NavItem, ...] = ()Alias for field number 0