티스토리 뷰

SWDesk

[Python] Download Images from Web

bizmaker 2021. 4. 24. 11:32

웹에서 이미지 다운로드하기

 

                imgSrcs = elem4.find_elements_by_css_selector('.se-image-resource')
                date21 = self.GetDate(date1)
                date22 = str(date21['Year'])+str(date21['Month'])+str(date21['Day'])+str(date21['Hour'])
                imageNumber = self.DownloadImages(imgSrcs, writer1[0:2]+date22)
    def DownloadImages(self, imageSources, fileInitial):
        imageList = []
        imgCount = 0
        for img1 in imageSources:
            imageList.append(img1.get_attribute('src'))
            imgCount += 1

        if not imageList: return None

        for index, link in enumerate(imageList):
            start1 = link.rfind('.')
            end1 = link.rfind('?')
            fileType = link[start1:end1]
            filePathname = self.ImageFolderPath + "/" + fileInitial + "_"+str(index) + fileType
            urlretrieve(link, filePathname)
        return imgCount
반응형

'SWDesk' 카테고리의 다른 글

[Python] Word2Vec 예제  (0) 2021.04.29
[Python] 단어 구름 네트워크  (0) 2021.04.25
series2supervised 변환 예제  (0) 2021.04.10
[Python] 카페 게시글 크롤링 프로그램 소스  (2) 2021.03.31
DataFrame 예제  (0) 2021.03.18