Source code for scraper_toolkit.components.Selector

from typing import Callable


[docs]class Selector: """Represent a CSS selector with an optional name and target attribute, with an optional post-processing function. :param selector_str: CSS selector as a string. :param name: Optional name for the parsed attribute, useful for creating the header row when exporting as a CSV file. :param attribute: HTML attribute of the element to store :param post_processing: Optional function called on the parsed attribute before it is stored. Useful for cleaning up and splitting data. """ def __init__(self, selector_str: str, name: str = None, attribute: str = None, post_processing: Callable = None): self.name = name self.selector_str = selector_str self.attribute = attribute self.post_processing = post_processing def __hash__(self): return hash((self.selector_str, self.attribute)) def __eq__(self, other): if isinstance(other, Selector): return hash(self) == hash(other)