Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

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 :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

@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?

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading