이미지를 크롤링하여 다운로드 할때 생기는 오류

조회수 225회

타오바오 사진들을 url 크롤링하고 이미지를 저장하려고 하는데요.

img src에 있는 사진들을 다운로드 하려고 하는데,

다운로드가 되는것도있고, 안되는것도 있습니다.

대부분 다운로드가 되지 않고요.

Find and download images

            for sub_wrap in sub_wrap_elements:
                description_div = sub_wrap.find('div', id='description')
                if description_div:
                    p_tags = description_div.find_all('p')
                    for p in p_tags:
                        img_tags = p.find_all('img')
                        for img in img_tags:
                            img_src = img.get('src')
                            if img_src:
                                # Download the image
                                response = requests.get(img_src)
                                if True:
                                    img_data = response.content
                                    image_name = img_src.split('/')[-1]  # Get the image filename

                                    # Get the script directory
                                    script_directory = os.path.dirname(os.path.abspath(__file__))

                                    # Create folder structure and save image in the script directory
                                    thumbnail_folder, body_folder = create_folder_structure(excel_filename, i)
                                    image_path = os.path.join(script_directory, body_folder, image_name)
                                    with open(image_path, 'wb') as f:
                                        f.write(img_data)
                                    debug_text.insert(tk.END, f"Downloaded image: {image_name}\n")
                                    root.update_idletasks()
                                else:
                                    debug_text.insert(tk.END, f"Failed to download image: {img_src}\n")
                                    root.update_idletasks()

어떤부분이 문제일까요..?

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

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

(ಠ_ಠ)
(ಠ‿ಠ)