+ 1

How to distinguish between two identical tags when using BeautifulSoup?

Hello everyone, how are you? I have a question when using the BeatifulSoup library. When I need to check two identical tags can I distinguish them by the class name? I have tried the following: soup.select_one("span[span-class-name]").text However, this command returns me a None object and consequently an attribute error: AttributeError: 'NoneType' object has no attribute 'text' I've also tried the following, but it's another method that returns a None object: soup.findAll("span[span-class-name]") The tag I'm trying to access is as follows: <span class="span-class-name">Some-String</span> What am I doing wrong?

31st Aug 2018, 9:41 PM
rfPeixoto
rfPeixoto - avatar
2 odpowiedzi
+ 1
In BeautifulSoup 4 it’s find_all. First parameter is the element and second is dictionary of attributes. soup.find_all(”span”, {”class”: ”span-class-name”)
31st Aug 2018, 9:50 PM
Toni Isotalo
Toni Isotalo - avatar
+ 1
Great thanks a lot! It works perfectly now.
31st Aug 2018, 10:13 PM
rfPeixoto
rfPeixoto - avatar