문제

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