+ 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?
2 Antworten
+ 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”)
+ 1
Great thanks a lot! It works perfectly now.