How to use the soupsieve.closest 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_api.py View on Github external
markup = """
        <article id="article">
          <div id="div-01">Here is div-01
            <div id="div-02">Here is div-02
              <div id="div-04">Here is div-04</div>
              <div id="div-03">Here is div-03</div>
            </div>
            <div id="div-05">Here is div-05</div>
          </div>
        </article>
        """

        soup = self.soup(markup, 'html.parser')
        el = sv.select_one('#div-03', soup)
        self.assertTrue(sv.closest('#div-02', el).attrs['id'] == 'div-02')
github facelessuser / soupsieve / tests / test_api.py View on Github external
markup = """
        <article id="article">
          <div id="div-01">Here is div-01
            <div id="div-02">Here is div-02
              <div id="div-04">Here is div-04</div>
              <div id="div-03">Here is div-03</div>
            </div>
            <div id="div-05">Here is div-05</div>
          </div>
        </article>
        """

        soup = self.soup(markup, 'html.parser')
        el = sv.select_one('#div-03', soup)
        self.assertTrue(sv.closest('div #div-05', el) is None)
        self.assertTrue(sv.closest('a', el) is None)
github facelessuser / soupsieve / tests / test_api.py View on Github external
markup = """
        <article id="article">
          <div id="div-01">Here is div-01
            <div id="div-02">Here is div-02
              <div id="div-04">Here is div-04</div>
              <div id="div-03">Here is div-03</div>
            </div>
            <div id="div-05">Here is div-05</div>
          </div>
        </article>
        """

        soup = self.soup(markup, 'html.parser')
        el = sv.select_one('#div-03', soup)
        self.assertTrue(sv.closest('div #div-05', el) is None)
        self.assertTrue(sv.closest('a', el) is None)
github facelessuser / soupsieve / tests / test_api.py View on Github external
markup = """
        <article id="article">
          <div id="div-01">Here is div-01
            <div id="div-02">Here is div-02
              <div id="div-04">Here is div-04</div>
              <div id="div-03">Here is div-03</div>
            </div>
            <div id="div-05">Here is div-05</div>
          </div>
        </article>
        """

        soup = self.soup(markup, 'html.parser')
        el = sv.select_one('#div-03', soup)
        self.assertTrue(sv.closest('article &gt; div', el).attrs['id'] == 'div-01')
        self.assertTrue(sv.closest(':not(div)', el).attrs['id'] == 'article')
github facelessuser / soupsieve / tests / test_soupsieve.py View on Github external
<div id="div-04">Here is div-04</div>
              <div id="div-03">Here is div-03</div>
            
            <div id="div-05">Here is div-05</div>
          
        
        """

        soup = bs4.BeautifulSoup(markup, 'html5lib')
        el = sv.select_one('#div-03', soup)

        self.assertTrue(sv.closest('#div-02', el).attrs['id'] == 'div-02')
        self.assertTrue(sv.closest('div div', el).attrs['id'] == 'div-03')
        self.assertTrue(sv.closest('article &gt; div', el).attrs['id'] == 'div-01')
        self.assertTrue(sv.closest(':not(div)', el).attrs['id'] == 'article')
        self.assertTrue(sv.closest('div #div-05', el) is None)
        self.assertTrue(sv.closest('a', el) is None)
github facelessuser / soupsieve / tests / test_api.py View on Github external
markup = """
        <article id="article">
          <div id="div-01">Here is div-01
            <div id="div-02">Here is div-02
              <div id="div-04">Here is div-04</div>
              <div id="div-03">Here is div-03</div>
            </div>
            <div id="div-05">Here is div-05</div>
          </div>
        </article>
        """

        soup = self.soup(markup, 'html.parser')
        el = sv.select_one('#div-03', soup)
        self.assertTrue(sv.closest('article &gt; div', el).attrs['id'] == 'div-01')
        self.assertTrue(sv.closest(':not(div)', el).attrs['id'] == 'article')
github facelessuser / soupsieve / tests / test_api.py View on Github external
markup = """
        <article id="article">
          <div id="div-01">Here is div-01
            <div id="div-02">Here is div-02
              <div id="div-04">Here is div-04</div>
              <div id="div-03">Here is div-03</div>
            </div>
            <div id="div-05">Here is div-05</div>
          </div>
        </article>
        """

        soup = self.soup(markup, 'html.parser')
        el = sv.select_one('#div-03', soup)
        self.assertTrue(sv.closest('div div', el).attrs['id'] == 'div-03')
github facelessuser / soupsieve / tests / test_soupsieve.py View on Github external
markup = """
        <article id="article">
          <div id="div-01">Here is div-01
            <div id="div-02">Here is div-02
              <div id="div-04">Here is div-04</div>
              <div id="div-03">Here is div-03</div>
            </div>
            <div id="div-05">Here is div-05</div>
          </div>
        </article>
        """

        soup = bs4.BeautifulSoup(markup, 'html5lib')
        el = sv.select_one('#div-03', soup)

        self.assertTrue(sv.closest('#div-02', el).attrs['id'] == 'div-02')
        self.assertTrue(sv.closest('div div', el).attrs['id'] == 'div-03')
        self.assertTrue(sv.closest('article &gt; div', el).attrs['id'] == 'div-01')
        self.assertTrue(sv.closest(':not(div)', el).attrs['id'] == 'article')
        self.assertTrue(sv.closest('div #div-05', el) is None)
        self.assertTrue(sv.closest('a', el) is None)