Exemplo n.º 1
0
 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
Exemplo n.º 2
0
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
Exemplo n.º 3
0
def select(selector: SelectorList, string_selector: str) -> SelectorList:
    return selector.css(string_selector)
Exemplo n.º 4
0
import logging