How to use the soupsieve.match function in soupsieve

To help you get started, we’ve selected a few soupsieve 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 facelessuser / soupsieve / tests / test_level4.py View on Github external
"""

        self.assert_selector(
            markup,
            "html:dir(ltr)",
            ['0'],
            flags=util.HTML
        )

        # Input is root
        for parser in ('html.parser', 'lxml', 'html5lib'):
            markup = """<input dir="auto" type="text" id="1">"""
            soup = bs4.BeautifulSoup(markup, parser)
            fragment = soup.input.extract()
            self.assertTrue(sv.match(":root:dir(ltr)", fragment, flags=sv.DEBUG))
github facelessuser / soupsieve / tests / test_api.py View on Github external
<p id="1"><code id="2"></code><img src="./image.png" id="3"></p>
        <pre id="4"></pre>
        <p><span class="some-class" id="5"></span><span id="some-id"></span></p>
        <pre class="ignore" id="6">            
        </pre>
        
        
        """

        soup = self.soup(markup, 'html.parser')
        nodes = sv.select('span[id]', soup)
        self.assertTrue(sv.match('span#\\35', nodes[0]))
        self.assertFalse(sv.match('span#\\35', nodes[1]))
github facelessuser / soupsieve / tests / test_soupsieve.py View on Github external
<p id="1"><code id="2"></code><img src="./image.png" id="3"></p>
        <pre id="4"></pre>
        <p><span class="some-class" id="5"></span><span id="some-id"></span></p>
        <pre class="ignore" id="6">            
        </pre>
        
        
        """

        soup = bs4.BeautifulSoup(markup, 'html5lib')
        nodes = sv.select('span[id]', soup)
        self.assertTrue(sv.match('span#\\35', nodes[0]))
        self.assertFalse(sv.match('span#\\35', nodes[1]))
github facelessuser / soupsieve / tests / test_api.py View on Github external
def test_invalid_type_input_match(self):
        """Test bad input into the match API."""

        flags = sv.DEBUG

        with self.assertRaises(TypeError):
            sv.match('div', "not a tag", flags=flags)
github facelessuser / soupsieve / tests / test_soupsieve.py View on Github external
<p id="1"><code id="2"></code><img src="./image.png" id="3"></p>
        <pre id="4"></pre>
        <p><span class="some-class" id="5"></span><span id="some-id"></span></p>
        <pre class="ignore" id="6">            
        </pre>
        
        
        """

        soup = bs4.BeautifulSoup(markup, 'html5lib')
        nodes = sv.select('span[id]', soup)
        self.assertTrue(sv.match('span#\\35', nodes[0]))
        self.assertFalse(sv.match('span#\\35', nodes[1]))