title: How can I find a table after a text string using BeautifulSoup in Python?
body: <p>I am trying to extract data from several web pages which are not uniform in how they display their tables.  I need to write code that will search for a text string and then go to the table immediately following that specific text string.  Then I want to extract the contents of that table.  Here's what I've got so far:</p>
  
  <pre><code>from BeautifulSoup import BeautifulSoup, SoupStrainer
  import re
  
  html = ['&lt;html&gt;&lt;body&gt;&lt;p align="center"&gt;&lt;b&gt;&lt;font size="2"&gt;Table 1&lt;/font&gt;&lt;/b&gt;&lt;table&gt;&lt;tr&gt;&lt;td&gt;1. row 1, cell 1&lt;/td&gt;&lt;td&gt;1. row 1, cell 2&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;1. row 2, cell 1&lt;/td&gt;&lt;td&gt;1. row 2, cell 2&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;&lt;p align="center"&gt;&lt;b&gt;&lt;font size="2"&gt;Table 2&lt;/font&gt;&lt;/b&gt;&lt;table&gt;&lt;tr&gt;&lt;td&gt;2. row 1, cell 1&lt;/td&gt;&lt;td&gt;2. row 1, cell 2&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;2. row 2, cell 1&lt;/td&gt;&lt;td&gt;2. row 2, cell 2&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;&lt;/html&gt;']
  soup = BeautifulSoup(''.join(html))
  searchtext = re.compile('Table 1',re.IGNORECASE) # Also need to figure out how to ignore space
  foundtext = soup.findAll('p',text=searchtext)
  soupafter = foundtext.findAllNext()
  table = soupafter.find('table') # find the next table after the search string is found
  rows = table.findAll('tr')
  for tr in rows:
      cols = tr.findAll('td')
      for td in cols:
          try:
              text = ''.join(td.find(text=True))
          except Exception:
              text = ""
          print text+"|",
  print
  </code></pre>
  
  <p>However, I get the following error:</p>
  
  <pre><code>    soupafter = foundtext.findAllNext()
  AttributeError: 'ResultSet' object has no attribute 'findAllNext'
  </code></pre>
  
  <p>Is there an easy way to do this using BeautifulSoup?</p>