質問

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