import os
from urllib.request import urlretrieve
if not os.path.isdir("경로/폴더이름") :
os.mkdir("경로/폴더이름")
print("폴더생성 완료")
else :
print("폴더가 이미 존재합니다")
img=soup.select('데이터위치')
img[0].text --->> x
img[0]['src'] -->> o
?.text 는 열린 태그와 닫는 태그 사이에 있는 컨텐츠를 가져옴
img_list = []
for i in img :
img_list.append(i['src'])
from selenium.webdriver.common.keys import Keys
body=driver.find_element(By.CSS_SELECTOR, 'body')
for i in range(횟수) :
body.send_keys(Keys.END)
time.sleep(1)
urlretrieve(img_list[i],'경로'+str(i)+'.jpg' )
를 이용해서
for i in range(len(img_list)):
urlretrieve(img_list[i],'경로'+str(i)+'.jpg' )
-----------------------------------------------------
최종코드

----------------------------------------------------------------------


주의 :
C:\Users\smhrd\Desktop
이게 원래 경로라면
파이썬에서는
C:/Users/smhrd/Desktop
이런식으로 역슬래쉬를 슬래쉬로 바꿔줘야함!!
-----------------------------------------------------------------
'Crawling' 카테고리의 다른 글
지마켓 상품정보 가져오기 ( driver.back() ) (0) | 2022.07.07 |
---|---|
한솥도시락 메뉴 가격 데이터 수집하기 ( element와 elements / try와 except / time 라이브러리 ) (0) | 2022.07.06 |
Selenium 라이브러리 설치 / 크롬 드라이버 설치 / 드라이버 실행하기 / (0) | 2022.07.06 |
영화 리뷰 데이터 분석 실습 (0) | 2022.07.06 |
영화 평점 데이터 수집 실습 ( list형태의 <태그> 결과값을 *[i].text로 바꾸고 새로운 list에 append하기 / list.set_index('name')으로 인덱덱스 번호 설정) (0) | 2022.07.05 |