python 질문드립니다. srcset 이미지 가져오기

매출이 오르면 내리는 수수료! 지금 수수료센터에서 전자결제(PG)수수료 비교견적 신청해 보세요!
python 질문드립니다. srcset 이미지 가져오기

QA

python 질문드립니다. srcset 이미지 가져오기

본문

안녕하세요.

python 으로 아래 문장 크롤링을 하고 싶습니다.

아래 같은 똑같은 문장이 100개정도 있으므로 for문으로 계속가져와야 합니다.

div.w-full.absolute.left-0.bottom-10.flex-center.flex-col

안에있는 srcset webp, png, 제목을 가져오고 싶습니다.

감사합니다.

 

 

epi_url         = urlopen('https://aaa.com/1.php')

soup            = BeautifulSoup(epi_url.read(), 'html.parser')

imgs            = soup.select('div.w-full.absolute.left-0.bottom-10.flex-center.flex-col img') #요소 선택

i = 1

for anchor in imgs.select("source"):      

     main_img    = anchor.get('srcset')

     anchor_type = anchor.get('type')

     

      webp = "webp 이미지 가져오기"

      png   = "png 이미지 가져오기"

      title   = "오징어 말이 된다  가져오기"

 

 

=== 1.php =====

<div class="w-full absolute left-0 bottom-10 flex-center flex-col">
                    <picture class="">
                        <source type="image/webp" srcset="https://aaa.com/688eca70-7166-4b54-a9e1-3309d6e0b412.webp">
                        <source type="image/png" srcset="https://aaa.com/688eca70-7166-4b54-a9e1-3309d6e0b412.png">
                        <img src="aaa.com/688eca70-7166-4b54-a9e1-3309d6e0b412.png" alt="오징어 말이 된다" class="w-full max-w-[115px] lg:max-w-[150px] mx-auto my-0">
                    </picture>
                    <p class="whitespace-pre-wrap break-all break-words support-break-word overflow-hidden text-ellipsis opacity-70 s10-regular-white px-8 mt-4 text-center" style="width: 100%; -webkit-line-clamp: 1; -webkit-box-orient: vertical; display: -webkit-box;">
                        강아지, 고양이
                    </p>
                </div>

 

이 질문에 댓글 쓰기 :

답변 1

wfull = soup.select('div.w-full')

for picture in (wfull):
  main_img = picture.find("img")["src"]
  title = picture.find("img")["alt"]

  source = picture.select("source")    
  webp = source[0]['srcset'] 
  png   = source[1].get('srcset')

 

webp, png 두가지 위와 같이해도 동일한 처리를 합니다

 

 

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

회원로그인

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