Question: I want to extract the value of a span via a CSS selector

```
soup = BeautifulSoup("<body><main><div class='rentalprice'><span>3.000</span></div></main></body>")
pagecontent = soup.find('body')

price = pagecontent.main.div.span.text # this line works although it's not suitable for production since I've now ignored the div class selector

#I then tried this:
price = pagecontent.select('main div.rentalprice span').text

```

The last line throws error:

> 
> Exception has occurred: AttributeError. ResultSet object has no attribute 'text'. You're probably treating a list of elements like a single element. Did you call find\_all() when you meant to call find()?
> 
> 
> 

How can I fix this? I don't want to use a for loop since there's only 1 span that matches.

I already checked:
[How to get text from span tag in BeautifulSoup](https://stackoverflow.com/questions/38133759/how-to-get-text-from-span-tag-in-beautifulsoup)
[Get value of attribute using CSS Selectors with BeutifulSoup](https://stackoverflow.com/questions/26803272/get-value-of-attribute-using-css-selectors-with-beutifulsoup)
[Python Selenium CSS Selector by Span get\_attribute](https://stackoverflow.com/questions/31661145/python-selenium-css-selector-by-span-get-attribute)

Answer: 
`select` returns a list of elements, but you can only use `.text` on a single element.

If you're sure that there's only 1 span that matches, you can target the first element in the list returned by `select`:

```
price = pagecontent.select('main div.rentalprice span')[0].text
print(price) # 3.000

```

Otherwise, you can use a for loop:

```
for elem in pagecontent.select('main div.rentalprice span'): 
    print(elem.text)

```
use `.find()`

```
from bs4 import BeautifulSoup

soup = BeautifulSoup("<body><main><div class='rentalprice'><span>3.000</span></div></main></body>", 'html.parser')
pagecontent = soup.find('body')
price = pagecontent.find('span').text
print(price) # 3.000

```