title: BeautifulSoup find the next specific tag following a found tag
body: <p>Given the following (simplified from a larger document)</p>
  
  <pre><code>&lt;tr class="row-class"&gt;
    &lt;td&gt;Age&lt;/td&gt;
    &lt;td&gt;16&lt;/td&gt;
  &lt;/tr&gt;
  &lt;tr class="row-class"&gt;
    &lt;td&gt;Height&lt;/td&gt;
    &lt;td&gt;5.6&lt;/td&gt;
  &lt;/tr&gt;
  &lt;tr class="row-class"&gt;
    &lt;td&gt;Weight&lt;/td&gt;
    &lt;td&gt;103.4&lt;/td&gt;
  &lt;/tr&gt;
  </code></pre>
  
  <p>I have tried to return the <code>16</code> from the appropriate row using <code>bs4</code> and <code>lxml</code>. The issue seems to be that there is a <code>Navigable String</code> between the two <code>td</code> tags, so that </p>
  
  <pre><code>page.find_all("tr", {"class":"row-class"})
  </code></pre>
  
  <p>yields a result set with </p>
  
  <pre><code>result[0] = {Tag} &lt;tr class="row-class"&gt; &lt;td&gt;Age&lt;/td&gt; &lt;td&gt;16&lt;/td&gt; &lt;/tr&gt;
  result[1] = {Tag} &lt;tr class="row-class"&gt; &lt;td&gt;Height&lt;/td&gt; &lt;td&gt;5.6&lt;/td&gt; &lt;/tr&gt;
  result[2] = {Tag} &lt;tr class="row-class"&gt; &lt;td&gt;Weight&lt;/td&gt; &lt;td&gt;103.4&lt;/td&gt; &lt;/tr&gt;
  </code></pre>
  
  <p>which is great, but I can't get the string in the second <code>td</code>. The contents of each of these rows is similar to</p>
  
  <pre><code>[' ', &lt;td&gt;Age&lt;/td&gt;, ' ', &lt;td&gt;16&lt;/td&gt;, ' ']
  </code></pre>
  
  <p>with the <code>td</code> being a <code>tag</code> and the <code>' '</code> being a <code>Navigable String</code>. This difference is preventing me from using the <code>next_element</code> or <code>next_sibling</code> convenience methods to access the correct text with something like:</p>
  
  <p>If I use:</p>
  
  <pre><code>find("td", text=re.compile(r'Age')).get_text()
  </code></pre>
  
  <p>I get <code>Age</code>. But if I try to access the next element via</p>
  
  <pre><code>find("td", text=re.compile(r'Age')).next_element()
  </code></pre>
  
  <p>I get </p>
  
  <blockquote>
    <p>'NavigableString' object is not callable</p>
  </blockquote>
  
  <p>Because of the wrapping <code>NavigableStrings</code> in the <code>result</code>, moving backwards with <code>previous_element</code> has the same problem.</p>
  
  <p>How do I move from the found <code>Tag</code> to the next <code>Tag</code>, skipping the <code>next_element</code> in between? Is there a way to remove these <code>' '</code> from the <code>result</code>? </p>
  
  <p>I should point out that I've already tried to be pragmatic with something like:</p>
  
  <pre><code>    for r in (sp.find_all("tr", {"class":"row-class"})):
          age = r.find("td", text=re.compile(r"\d\d")).get_text()
  </code></pre>
  
  <p>it works ... until I parse a document that has another order with a matching <code>\d\d</code> before <code>Age</code>. </p>
  
  <p>I know, also, that I can </p>
  
  <pre><code>find("td", text=re.compile(r'Age')).next_sibling.next_sibling
  </code></pre>
  
  <p>but that is hard-baking the structure in.</p>
  
  <p>So I need to be specific in the search and find the <code>td</code> that has the target string, then find the value in the next <code>td</code>. I know I could build some logic that tests each row, but it seems like I'm missing something obvious and more elegant...</p>