title: BeautifulSoup and Searching By Class
body: <blockquote>
    <p><strong>Possible Duplicate:</strong><br>
    <a href="https://stackoverflow.com/questions/1242755/beautiful-soup-cannot-find-a-css-class-if-the-object-has-other-classes-too">Beautiful Soup cannot find a CSS class if the object has other classes, too</a>  </p>
  </blockquote>
  
  
  
  <p>I'm using BeautifulSoup to find <code>tables</code> in the HTML. The problem I am currently running into is the use of spaces in the <code>class</code> attribute. If my HTML reads <code>&lt;html&gt;&lt;table class="wikitable sortable"&gt;blah&lt;/table&gt;&lt;/html&gt;</code>, I can't seem to extract it with the following (where I was to be able to find <code>tables</code> with both <code>wikipedia</code> and <code>wikipedia sortable</code> for the <code>class</code>):</p>
  
  <pre><code>BeautifulSoup(html).findAll(attrs={'class':re.compile("wikitable( sortable)?")})
  </code></pre>
  
  <p>This will find the table if my HTML is just <code>&lt;html&gt;&lt;table class="wikitable"&gt;blah&lt;/table&gt;&lt;/html&gt;</code> though. Likewise, I have tried using <code>"wikitable sortable"</code> in my regular expression, and that won't match either. Any ideas?</p>