from urllib.request import urlretrieve
imgUrl = "원하는 이미지의url"
saveDir = "test.jpg"
urlretrieve(imgUrl, saveDir)
def createDirectory(keyword):
if os.path.isdir(keyword) == False:
os.mkdir(keyword)
print(f"{keyword} 폴더 생성 완료")
else:
print(f"{keyword} 폴더는 이미 존재합니다")
keyword = "빅토리아시크릿 쇼"
img_url = f"https://search.naver.com/search.naver?where=image&sm=tab_jum&query={keyword}"
driver = wb.Chrome()
driver.get(img_url)
time.sleep(1)
for i in range(10):
driver.find_element(By.TAG_NAME, value="body").send_keys(Keys.END)
time.sleep(1)
imgs = driver.find_elements(By.CSS_SELECTOR, value="img._image._listImage")
imgUrlList=[]
for img in tqdm(imgs):
imgUrlList.append(img.get_attribute('src'))
createDirectory(keyword)
pic_num = 1
for url in tqdm(imgUrlList):
# url이 'data'로 시작하는 값은 저장되지 않도록 조건문 추가
if url.startswith("data"):
continue
else:
saveDir = f"{keyword}/{keyword}{pic_num}.jpg"
urlretrieve(url, saveDir)
pic_num += 1
driver.quit()
입력창의 id 값이 이러한 숫자들이 붙어있다면 안 찾아질 확률이 높으므로 그냥 class 이름으로 찾는것이 좋다.
driver.switch_to.frame("iframe 명")
driver.switch_to.default_content()
driver.switch_to.window
driver.switch_to.alert
map_url="https://map.naver.com/v5/?c=14128481.8864457,4183753.1546020,16,0,0,0,dh"
driver = wb.Chrome()
driver.get(map_url)
driver.find_element(By.CLASS_NAME, value='input_search').send_keys("카페\n")
time.sleep(3)
driver.switch_to.frame("searchIframe")
stores = driver.find_elements(By.CSS_SELECTOR, value="a._3nCBm")
for i in range(len(stores)):
stores[i].click()
driver.switch_to.default_content()
time.sleep(1)
driver.switch_to.frame("entryIframe")
title = driver.find_element(By.CSS_SELECTOR, value="span._3XamX").text
print(title)
driver.switch_to.default_content()
driver.switch_to.frame("searchIframe")
time.sleep(1)