<html><head> <title>Test</title></head>
<body>
<table> <tr class='test hidden'><td>foo</td></tr> <tr class='full'><td>bar</td></tr> <tr class='test hidden'><td>foo</td></tr> <tr class='full'><td>bar</td></tr> </table>
</body>
</html>
# import librariesimport urllib2import refrom bs4 import BeautifulSoupfrom bs4 import Commentimport operator
with open('sample.html', 'r') as myfile: html=myfile.read()
soup = BeautifulSoup(html, 'html.parser')rows = soup.find('table').find_all('tr', class_=lambda x: 'hidden' not in x)
for row in rows: print row
<tr class="test hidden"><td>foo</td></tr><tr class="full"><td>bar</td></tr><tr class="test hidden"><td>foo</td></tr><tr class="full"><td>bar</td></tr>
<tr class="full"><td>bar</td></tr>
<tr class="full"><td>bar</td></tr>
rows = soup.find('table').find_all('tr')
for row in rows:
if 'hidden' not in row.get('class', ''):
print(row)
for row in soup.table.find_all('tr'):
if 'hidden' not in row.get('class'):
print(row)
rows = soup.table.find('tr', class_=lambda x: print(x))
test
hidden
test hidden
full
full
test
hidden
test hidden
full
full
rows = soup.find('table').find_all(
lambda tag: tag.name == 'tr' and 'hidden' not in tag.get('class', '')
)