Dec-30-2017, 10:24 AM
I am retrieving data from a webpage using beautifulsoup. There I observed in the code that same class name is applied multiple times from where I want to retrieve the data.
For example-
I also tried this -
I want to know the solution, how can I retrieve the data either one by one or at time?
For example-
print(soup.find(class_="_2lzr _50f5 _50f7").text)above is the code I am using to retrieve the data. I observed in the html code that there are multiple classes with the name "_2lzr _50f5 _50f7", but this print statement only prints the text of first one.
I also tried this -
print(soup.find_all(class_="_2lzr _50f5 _50f7").text)but I am getting an error like below -
Error:Traceback (most recent call last):
File "data_fetching.py", line 15, in <module>
print(soup.find_all(class_="_2lzr _50f5 _50f7").text)
File "/usr/lib/python3.6/site-packages/bs4/element.py", line 1807, in __getattr__
"ResultSet object has no attribute '%s'. You're probably treating a list of items like a single item. 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 items like a single item. Did you call find_all() when you meant to call find()?
though the soup selects the all with class name "_2lzr _50f5 _50f7" but not able to display the text.I want to know the solution, how can I retrieve the data either one by one or at time?