Find_all and select difference, BeautifoulSoup


Hello, everyone.

Someone could clarify for me exactly what is the difference between using “find_all” and “select” when using “BeautifulSoup’s”. At first I thought that select would be used to point to CSS, however I see (or think I understand) that it’s pointing to a class in the same way we would do with find_all or the methods explained above, so I don’t understand the particular use of this function in this case.

Thanks to all of you

I had to look this up myself, and I found this section of the Beautifulsoup documentation instructive.

Particularly this:

So what I takeaway from this is that .select() can be useful when you want to search for tags that match two or more css classes and you want it to work no matter what order the classes are used in.

It looks like select() supports a wide range of formats to specify intricate selector behavior, you can see a lot of them here

I hope this helps!


Very useful, thank you very much!

1 Like

Hi, I tried using this method here

the code:
total_plays ="#total-plays")[0]
patriots_total_plays_count ="td")[2].text

how come I can’t use both the total-plays id and “td” in the same .select statement?
e.g total_plays ="#total-plays", "td")[0]

I get the error TypeError: ‘str’ object is not callable

with find_all, I can do parser.find_all("p", class = "inner_text")

in the slide on “Nesting CSS selectors” we have examples such as body div #first, and div p.
do i need to call a separate .select for body, div and #first?


As refer back to the question, this is because total-plays id and “td” are not in the same <> , therefore there’s no item fulfil the condition of having both total-plays id and td. Also, the syntax should be“Selector1Selector2”) instead of having them separated by comma.

Side note, I couldn’t manage to filter out the item when my selector 1 is class but my selector 2 is id though. It works with both selector being class or few other ways except 1 class 1 id. Anyone know why?

test_a =".stats_table#team_stats") ( This can’t work )
test_b =“table #team_stats”) ( This works )