python 특정단어 체크

매출이 오르면 내리는 수수료! 지금 수수료센터에서 전자결제(PG)수수료 비교견적 신청해 보세요!
python 특정단어 체크

QA

python 특정단어 체크

본문

안녕하세요.

python에서 특정단어가 포함되어 있는지 체크할수 있는 방법이

있나요?

아래 div 안에 image 파일명에 특정단어를 확인해서

예를 들어

backImage_b8.png -> backImage 단어를 찾아서 파일을 분기하고 싶습니다.

div안에 3개의 파일이 있을수도 있고 2개의 파일이 있을수도 있어서

특정단어를 찾아서 분기를 해야 될거 같습니다.

감사합니다.

 

 

<div class="area_thumbnail">

<img src="https://aaa.com/backImage_b8.png" width="218" height="174">
<img src="https://aaa.com/frontImage_b8.png" width="218" height="174">
<img src="https://aaa.com/objectImage_b8.png" width="218" height="174">

</div>

 

python code

for a in soup.select('div[class="area_thumbnail"] img'):

                area_thumbnail  = a['src']

                if thumbnail_name == 'backImage': 

                    save1 = "backImage_1.png" 

                elif thumbnail_name == 'frontImage': 

                    save1 = "frontImage_1.png" 

                elif thumbnail_name == 'objectImage': 

                    save1 = objectImage_1.png"

이 질문에 댓글 쓰기 :

답변 1

문자열 메서드를 사용하면 가능하지 않을까 합니다.

예를 들어 다음과 같이 해 볼 수 있을 것 같습니다.


for a in soup.select('div[class="area_thumbnail"] img'):
    area_thumbnail = a['src']
    
    if 'backImage' in area_thumbnail:
        save1 = "backImage_1.png"
    elif 'frontImage' in area_thumbnail:
        save1 = "frontImage_1.png"
    elif 'objectImage' in area_thumbnail:
        save1 = "objectImage_1.png"
    else:
        # 처리해야 할 다른 경우가 있을 경우에 대한 로직 추가
        pass

 

답변을 작성하시기 전에 로그인 해주세요.
전체 0
QA 내용 검색

회원로그인

(주)에스아이알소프트 / 대표:홍석명 / (06211) 서울특별시 강남구 역삼동 707-34 한신인터밸리24 서관 1404호 / E-Mail: admin@sir.kr
사업자등록번호: 217-81-36347 / 통신판매업신고번호:2014-서울강남-02098호 / 개인정보보호책임자:김민섭(minsup@sir.kr)
© SIRSOFT