BS4 text inside <span> which has no class

i am trying to scrape this 4.1 rating in span tag using this python code but it is returning empty.

for item in soup.select("._9uwBC wY0my"):
        n = soup.find("span").text()
        print(n)
---------------------------------------

<div class="_9uwBC wY0my">
      <span class="icon-star _537e4"></span>
      <span>4.1</span>
</div>

>Solution :

@Aditya, I think soup.find("span") will only return the first "span" and you want the text from the second one.
I would try:

spans = soup.find_all("span")
for span in spans:
    n = span.text()
    if n != '':
        print(n)

Which should print the text of the non-empty span tags.
Does accomplish what you want?

Leave a Reply