파이썬 질문입니다! AttributeError: 'str' object has no attribute 'text'

조회수 10243회

안녕하세요. 아래와 같이 돌리는 데 에러가 뜹니다. 특정 문자열들을 반복문을 통해 append 후 출력이 안되는 걸까요?

            items = driver.find_element(By.CLASS_NAME, 'items').text
            items_split = items.split("/")
            item_list = []
            for item in items_split:
                item_list.append(item.text)
            print(item_list)
AttributeError: 'str' object has no attribute 'text'

1 답변

  • 좋아요

    0

    싫어요
    채택 취소하기

    AttributeError: 'str' object has no attribute 'text'

    str 객체에는 text 요소가 없습니다. 이미 text명령으로 str로 치환된 데이터를 다시 한 번 str로 치환하려해서 생기는 문젭니다.

    items = driver.find_element(By.CLASS_NAME, 'items').text
    items_split = items.split("/")
    item_list = []
    for item in items_split:
        item_list.append(item)#(item.text)
    print(item_list)
    
    • 해결 되었습니다. 정말 감사합니다! 남선주 2022.1.19 13:34

답변을 하려면 로그인이 필요합니다.

프로그래머스 커뮤니티는 개발자들을 위한 Q&A 서비스입니다. 로그인해야 답변을 작성하실 수 있습니다.

(ಠ_ಠ)
(ಠ‿ಠ)