I am trying to get the class of a dl-element. I can print the class (see the first line) but i cant use that result in an if-statement (So "works" is never printed). I guess i am somehow wrong with my syntax. Am i? Believe me that there are lot of "method"-class elements in my tests - see below

 print(child.dl.get('class'))
    if child.dl.get('class')=="['method']":
        print("WORKS!")

This is the output of the first line:

['method']
['method']
['class']
['method']
['method']
['method']
['method']
['describe']
有帮助吗?

解决方案

child.dl.get('class') returns a list since class is a multi-valued attribute.

Check if method is inside the list:

if 'method' in child.dl.get('class', []):
    print("WORKS!")
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top