I have a quick question about the .select() function: when using this function, do we include a “.” before the name of the tag? Here’s an example:
cocoa_percents =
cocoa_percent_tags = soup.select(".CocoaPercent")
I have a quick question about the .select() function: when using this function, do we include a “.” before the name of the tag? Here’s an example:
cocoa_percents =
cocoa_percent_tags = soup.select(".CocoaPercent")
.select()
is not a function, .select
is a method. You will learn about classes later in the course. For now, I would just accept that method syntax is different from functions
methods belong to a specific class, for example .append()
:
[].append(3)
we can call .append()
on list (instance of list class), while .append() is not available for strings for example.
Got it, thanks. I tend to conflate functions and methods. But when we’re trying to select the “CocoaPercent” tag, why do we include write it as “.CocoaPercent”, with a period, as opposed to “CocoaPercent”, without a period? Apologies if this wasn’t clear in my original question
Oh, I should read the question better. Are you using python beautifulsoup?
this has to do with html, to select an element we would do the element name ("div"
) for example, but we can target elements by class (.className
) and id (#idName
) as well
why .
for class and #
for id? Not sure, that is something you would have to google.
Gotcha! That helps, this is exactly what I wasn’t remembering from the BeautifulSoup lessons. I forgot the class and id distinction here.
Thank you for your help!