<jupyter_start><jupyter_text>주소(url), 저장 위치(folder) 지정<jupyter_code>url = 'https://smartstore.naver.com/sopumdamoa/products/108740861'
folder = 'c:/til/img/'<jupyter_output><empty_output><jupyter_text>크롤링 실행<jupyter_code>from bs4 import BeautifulSoup as bs
from selenium import webdriver
import time
import re

# 페이지 열기
driver = webdriver.Chrome('./chromedriver.exe')
driver.get(url)

images = []

# 타이틀
html = driver.page_source
soup = bs(html, 'html.parser')
txt = soup.find('div', class_='CxNYUPvHfB').text
txt = re.sub('[^a-zA-Zㄱ-힇0-9 ]', '', txt)

# 메인 이미지
img = soup.find_all('div', class_='_23RpOU6xpc')[0].find('img')['data-src']
images.append(img)

# 상세 이미지
for i in range(2):
    driver.execute_script("window.scrollTo(0, document.body.scrollHeight);")
    time.sleep(0.5)
html = driver.page_source
soup = bs(html, 'html.parser')
div = soup.find('div', class_='_9F9CWn02VE').find_all('img')
for d in div:
    images.append(d['data-src'])
    
# 이미지 저장
for i, img in enumerate(images):
    name = folder + txt + '0' + str(i) + '.jpg'
    urllib.request.urlretrieve(img, name)
    
# 종료
driver.close()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.17559262510974538, 'fraction_numerical': 0.021949078138718173, 'mean_word_length': 5.031746031746032, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 1, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '2', 'dir': 'jupyter-structured-clean-dedup', 'id': '476444', 'license': 'MIT', 'n_tokens_mistral': 519, 'n_tokens_neox': 527, 'n_words': 84, 'path': '.ipynb_checkpoints/Untitled-checkpoint.ipynb', 'repo_name': 'DojunPark/TIL', 'size': '1139'}