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.
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!
Hi, I tried using this method here
total_plays = parser.select("#total-plays")
patriots_total_plays_count = total_plays.select("td").text
how come I can’t use both the total-plays id and “td” in the same .select statement?
total_plays = parser.select("#total-plays", "td")
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 parser.select(“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 = parser.select(".stats_table#team_stats") ( This can’t work )
test_b = parser.select(“table #team_stats”) ( This works )