Collectives™ on Stack Overflow
Find centralized, trusted content and collaborate around the technologies you use most.
Learn more about Collectives
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
Learn more about Teams
I created a simple scraper but I have a problem with changing
ResultSet
to text. I want to get the only text without a
href
etc. When I use
find
method it works good, but when I add
find_all
as a second method it shows error:
numberone = soup.find("span", itemprop="house").text <---- this works good
print(numberone)
numbertwo = soup.find("div", class_="interesting").find_all('a').text <---- this does not work
print(numbertwo)
Output for 'numberone' is good, but for 'numbertwo' it shows an error:
"ResultSet object has no attribute '%s'. You're probably treating a
list of elements like a single element. Did you call find_all() when
you meant to call find()?" % key 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()?
Maybe someone knows the solution?
–
it is because it returns a set of results, in order to print all the results you can use a for-loop like this:
results = numbertwo = soup.find("div", class_="interesting").find_all('a')
for result in results:
print(result.text)
–