How to use cssselect - 10 common examples

To help you get started, we’ve selected a few cssselect examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github mozilla / fjord / vendor / packages / cssselect / cssselect / tests.py View on Github external
def test_tokenizer(self):
        tokens = [
            _unicode(item) for item in tokenize(
                u(r'E\ é > f [a~="y\"x"]:nth(/* fu /]* */-3.7)'))]
        assert tokens == [
            u(""),
            "<s>",
            "' at 5&gt;",
            "<s>",
            # the no-break space is not whitespace in CSS
            u(""),  # f\xa0
            "",
            "",
            "",
            "",
            "",
            "",
            "",</s></s>
github zopyx / print-css-rocks / lessons / in-progress / lesson-multi-column-float-to-landscape / lib / python3.4 / site-packages / cssselect / tests.py View on Github external
def test_tokenizer(self):
        tokens = [
            _unicode(item) for item in tokenize(
                u(r'E\ é &gt; f&nbsp;[a~="y\"x"]:nth(/* fu /]* */-3.7)'))]
        assert tokens == [
            u(""),
            "<s>",
            "' at 5&gt;",
            "<s>",
            # the no-break space is not whitespace in CSS
            u(""),  # f\xa0
            "",
            "",
            "",
            "",
            "",
            "",
            "",</s></s>
github mozilla / fjord / vendor / packages / cssselect / cssselect / tests.py View on Github external
def test_unicode(self):
        if sys.version_info[0] &lt; 3:
            css = '.a\xc1b'.decode('ISO-8859-1')
        else:
            css = '.a\xc1b'

        xpath = GenericTranslator().css_to_xpath(css)
        assert css[1:] in xpath
        xpath = xpath.encode('ascii', 'xmlcharrefreplace').decode('ASCII')
        assert xpath == (
            "descendant-or-self::*[@class and contains("
            "concat(' ', normalize-space(@class), ' '), ' aÁb ')]")
github mozilla / fjord / vendor / packages / cssselect / cssselect / tests.py View on Github external
def test_unicode_escapes(self):
        # \22 == '"'  \20 == ' '
        css_to_xpath = GenericTranslator().css_to_xpath
        assert css_to_xpath(r'*[aval="\'\22\'"]') == (
            '''descendant-or-self::*[@aval = concat("'",'"',"'")]''')
        assert css_to_xpath(r'*[aval="\'\22 2\'"]') == (
            '''descendant-or-self::*[@aval = concat("'",'"2',"'")]''')
        assert css_to_xpath(r'*[aval="\'\20  \'"]') == (
            '''descendant-or-self::*[@aval = "'  '"]''')
        assert css_to_xpath('*[aval="\'\\20\r\n \'"]') == (
            '''descendant-or-self::*[@aval = "'  '"]''')
github mozilla / fjord / vendor / packages / cssselect / cssselect / tests.py View on Github external
def xpath(css):
            return _unicode(GenericTranslator().css_to_xpath(css, prefix=''))
github zopyx / print-css-rocks / lessons / in-progress / lesson-multi-column-float-to-landscape / lib / python3.4 / site-packages / cssselect / tests.py View on Github external
def test_quoting(self):
        css_to_xpath = GenericTranslator().css_to_xpath
        assert css_to_xpath('*[aval="\'"]') == (
            '''descendant-or-self::*[@aval = "'"]''')
        assert css_to_xpath('*[aval="\'\'\'"]') == (
            """descendant-or-self::*[@aval = "'''"]""")
        assert css_to_xpath('*[aval=\'"\']') == (
            '''descendant-or-self::*[@aval = '"']''')
        assert css_to_xpath('*[aval=\'"""\']') == (
            '''descendant-or-self::*[@aval = '"""']''')
github zopyx / print-css-rocks / lessons / in-progress / lesson-multi-column-float-to-landscape / lib / python3.4 / site-packages / cssselect / tests.py View on Github external
def series(css):
            selector, = parse(':nth-child(%s)' % css)
            args = selector.parsed_tree.arguments
            try:
                return parse_series(args)
            except ValueError:
                return None
github mozilla / fjord / vendor / packages / cssselect / cssselect / tests.py View on Github external
def specificity(css):
            selectors = parse(css)
            assert len(selectors) == 1
            return selectors[0].specificity()
github zopyx / print-css-rocks / lessons / in-progress / lesson-multi-column-float-to-landscape / lib / python3.4 / site-packages / cssselect / tests.py View on Github external
def repr_parse(css):
            selectors = parse(css)
            for selector in selectors:
                assert selector.pseudo_element is None
            return [repr(selector.parsed_tree).replace("(u'", "('")
                    for selector in selectors]
github zopyx / print-css-rocks / lessons / in-progress / lesson-multi-column-float-to-landscape / lib / python3.4 / site-packages / cssselect / tests.py View on Github external
def get_error(css):
            try:
                parse(css)
            except SelectorSyntaxError:
                # Py2, Py3, ...
                return str(sys.exc_info()[1]).replace("(u'", "('")