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 Get value of attribute using CSS Selectors with BeutifulSoup Python Selenium CSS Selector by Span get_attribute