Home > Software design >  BS4 text inside <span> which has no class
BS4 text inside <span> which has no class

Time:01-16

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 >
      <span ></span>
      <span>4.1</span>
</div>

CodePudding user response:

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

for item in soup.select("div._9uwBC.wY0my"):
    spans = item.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, under the you specified. Does accomplish what you want?

  •  Tags:  
  • Related