# Selenium을 이용하여
# 홈페이지 탐색(with Selenium)
# 콘솔창에 !pip install selenium
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
import time
import urllib.request
# chromedirver.exe 파일의 위치
path = "C:/User/Pyth/workspace/chromedriver"
# 크롤링할 사이트 주소
source_url = "http://madup.com"
driver = webdriver.Chrome(path)
driver.get(source_url)
# 1. 매드업 홈페이지의 상품소개서 열기
driver.find_element_by_css_selector(".fa.fa-download").click()

# 2. 매드업 홈페이지 내의 이미지 다운로드 받기
# 첫번째 이미지만 저장하기
driver = webdriver.Chrome()
driver.get("http://madup.com")
time.sleep(2)
img = driver.find_elements_by_css_selector(".img-mobile")[0].get_attribute('src')
urllib.request.urlretrieve(img,'test.jpg')
# 반복문으로 모든 이미지 저장하기
driver = webdriver.Chrome()
driver.get("http://madup.com")
time.sleep(2)
images = driver.find_elements_by_css_selector(".img-mobile")
count = 0
for image in images:
count = count + 1
for i in (0,len(driver.find_elements_by_css_selector(".img-mobile"))):
i = image.get_attribute('src')
urllib.request.urlretrieve(i,str(count)+'.jpg')










# 3. 매드업 홈화면을 캡쳐하여 이미지 파일로 저장하기
from selenium import webdriver
url = "http://madup.com"
driver = webdriver.Chrome("chromedriver")
driver.get(url)
driver.save_screenshot("madpup_home.png")
driver.quit()


카카오맵 클로링 포트폴리오 링크입니다.
'Python' 카테고리의 다른 글
파이썬, 함수형 프로그래밍 (일급 함수) (0) | 2023.06.25 |
---|---|
Python - 카카오맵 크롤링(with Selenium) (0) | 2021.07.26 |
Python - 시계열분석(TimeSeries) (0) | 2021.07.21 |
Python - 군집분석 (0) | 2021.07.20 |
Python - 의사결정나무(Decision Tree) (0) | 2021.07.16 |