Find_all and select difference, BeautifoulSoup

https://app.dataquest.io/m/54/web-scraping/8/using-css-selectors

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!

3 Likes

Very useful, thank you very much!

1 Like

Hi, I tried using this method here
https://app.dataquest.io/m/54/web-scraping/10/using-nested-css-selectors

the code:
total_plays = parser.select("#total-plays")[0]
patriots_total_plays_count = total_plays.select("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 = parser.select("#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?