I have an html document with 4 or 5 different tables. The one I want has an attribute class = "data". I can't figure out how to make BeautifulSoup return just that table.
soup = BeautifulSoup(myhtml)
t = soup.findAll('table', 'class="data"')
for table in t:
rows = table.findAll('tr')
for tr in rows:
cols = tr.findAll('td')
for td in cols:
print td
If I remove the 'class="data"' in the above, I get the results from every table. Is it possible to select only the one with class = "data". Or, is there some other way to iterate through the tables?
Specify the class
atttribute as a dictionary as follow:
t = soup.findAll('table', {'class': 'data'})
If you use bs4, you can use CSS Selector using select
method:
t = css_soup.select("table.data")
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments