def select_from(self, selector: SelectorList) -> SelectorList: selected = selector.css(self.string_selector) if not selected: msg = 'Not found any "{}" containers.'.format(self.name) if self.raise_on_missed: raise RuntimeError(msg) else: self.logger.warning(msg) return SelectorList([]) return selected
def childes( selector: SelectorList, parent_tag: str, ) -> SelectorList: if not isinstance(parent_tag, str): raise TypeError('Given `parent_tag` is not `str` object.') childes_selector = SelectorList() iterate_selector_string_template = parent_tag + ' > :nth-child({i})' i = 1 # starting the iteration while True: child = selector.css(iterate_selector_string_template.format(i=i)) if child: childes_selector.append(child) i += 1 else: return childes_selector
def select(selector: SelectorList, string_selector: str) -> SelectorList: return selector.css(string_selector)
import logging