BS4 text inside <span> which has no class

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


OK, here's one approach for getting the names and stars for each restaurant on the page. It's not necessarily the most elegant way to do it, but I've tried it a couple of times and it seems to work:

divs = soup.find_all('div')

for div in divs:
    if div.has_attr('class'):
        if div['class'] == ['nA6kb']: ## the class of the divs with the name
            name = div.text
            k = div.find_next('div') ## the next div
            l = k.find_next('div')  ## the div with the stars
            spans = l.find_all('span') ## this part is same as the answer above
            for span in spans:
                n = span.text
                if n != '':
                    print(name, n)

This assumes that the div that contains the stars span is always the second div after the div that contains the restaurant name. It looks like that's always the case, but I'm not positive that it never changes.