How to use Beautiful Soup to select only one of multiple tables

Michael T

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?

falsetru

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.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Beautiful Soup: Parsing only one element

From Dev

Issue with Tables and Beautiful Soup

From Dev

How to select tags by attribute value with Beautiful Soup

From Dev

Select values from two tables with multiple requirements but only use one of them

From Dev

sql - how to select multiple columns with only one distinct column from joining multiple tables

From Dev

How can I limit beautiful soup to extract information from one tab only?

From Dev

Find (Beautiful Soup) returns None in case the tag is only one

From Dev

Beautiful Soup nth-of-type selector selects only one element

From Dev

Beautiful Soup: Trying to select tags on conflicting multiple criteria

From Dev

Scraping multiple pages in one Beautiful Soup script -- getting same result

From Dev

Scraping multiple pages in one Beautiful Soup script -- getting same result

From Dev

HTML tables with python beautiful soup

From Dev

How to only select one multiple class with jQuery

From Dev

How to select div by text content using Beautiful Soup?

From Dev

How to select a class of div inside of a div with beautiful soup?

From Dev

how to select all "src" in below code for beautiful soup

From Dev

Python beautiful soup select text

From Dev

Beautiful soup select siblings not working

From Dev

How to use DateDiff into only one SELECT statement?

From Dev

How to get multiple titles using beautiful soup python

From Dev

How to use Beautiful Soup to extract string in <script> tag?

From Dev

How to use Beautiful Soup to extract string in <script> tag?

From Dev

How to click/use a link parsed from Beautiful Soup in python

From Dev

How to INSERT into multiple tables from one SELECT statement

From Dev

how to select one row in joining multiple tables based on a case statement

From Dev

There are multiple option I use to select only one using for?

From Dev

How to use count in SELECT query to create a view from multiple tables?

From Dev

How to use count in SELECT query to create a view from multiple tables?

From Dev

How to Rename a Class in Beautiful Soup

Related Related

  1. 1

    Beautiful Soup: Parsing only one element

  2. 2

    Issue with Tables and Beautiful Soup

  3. 3

    How to select tags by attribute value with Beautiful Soup

  4. 4

    Select values from two tables with multiple requirements but only use one of them

  5. 5

    sql - how to select multiple columns with only one distinct column from joining multiple tables

  6. 6

    How can I limit beautiful soup to extract information from one tab only?

  7. 7

    Find (Beautiful Soup) returns None in case the tag is only one

  8. 8

    Beautiful Soup nth-of-type selector selects only one element

  9. 9

    Beautiful Soup: Trying to select tags on conflicting multiple criteria

  10. 10

    Scraping multiple pages in one Beautiful Soup script -- getting same result

  11. 11

    Scraping multiple pages in one Beautiful Soup script -- getting same result

  12. 12

    HTML tables with python beautiful soup

  13. 13

    How to only select one multiple class with jQuery

  14. 14

    How to select div by text content using Beautiful Soup?

  15. 15

    How to select a class of div inside of a div with beautiful soup?

  16. 16

    how to select all "src" in below code for beautiful soup

  17. 17

    Python beautiful soup select text

  18. 18

    Beautiful soup select siblings not working

  19. 19

    How to use DateDiff into only one SELECT statement?

  20. 20

    How to get multiple titles using beautiful soup python

  21. 21

    How to use Beautiful Soup to extract string in <script> tag?

  22. 22

    How to use Beautiful Soup to extract string in <script> tag?

  23. 23

    How to click/use a link parsed from Beautiful Soup in python

  24. 24

    How to INSERT into multiple tables from one SELECT statement

  25. 25

    how to select one row in joining multiple tables based on a case statement

  26. 26

    There are multiple option I use to select only one using for?

  27. 27

    How to use count in SELECT query to create a view from multiple tables?

  28. 28

    How to use count in SELECT query to create a view from multiple tables?

  29. 29

    How to Rename a Class in Beautiful Soup

HotTag

Archive