I am having trouble with class attributes using Beautiful Soup.
My code is :
ls = ([x.get_text().strip('\n') for x in bs.find_all("div",{"class":"other-info","class":"description","class":"n-title search-detail"})])
But I get only description class not other class information. How can I get other class information in same code.
Firstly, you can use strip=True with the get_text() function to strip all the whitespace from the text. Secondly, a dictionary can't have duplicate keys. The find_all() function accepts a list as a value for an attribute. Also, those brackets () around the list are redundant. Remove them.
Use this:
ls = [x.get_text(strip=True) for x in bs.find_all("div", {"class": ["other-info", "description", "n-title search-detail"]})]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With