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

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

QA

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

답변 1

본문

안녕하세요.

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 두가지 위와 같이해도 동일한 처리를 합니다

 

 

답변을 작성하시기 전에 로그인 해주세요.
QA 내용 검색
질문등록
전체 0
© SIRSOFT
현재 페이지 제일 처음으로