์๋ฌ ๋ฐ์
์ ๋ ๊ฐ์ ๋ฌธ์ ์๊ฒจ์ ๊ตฌ๊ธ๋งํด๋ณด๋๊น ์๋ ๊ฒ ๋ฐ๊ฟ์ ๋์ด์ ใ
ใ
def imageDown(keyword): url = f'https://www.google.com.br/search?q={keyword}&source=lnms&tbm=isch' chrome_options = webdriver.ChromeOptions() chrome_options.add_argument('--headless') chrome_options.add_argument('--no-sandbox') chrome_options.add_argument('--disable-dev-shm-usage') driver = webdriver.Chrome('chromedriver', chrome_options=chrome_options) driver.get(url) body = driver.find_element(By.CSS_SELECTOR, 'body') # ํ์ด์ง ๋ค์ด์์ผ์ ๋ ๋ง์ ์ด๋ฏธ์ง๊ฐ ๋์ค๊ฒ ํ๋ค for i in range(30): body.send_keys(Keys.PAGE_DOWN) time.sleep(0.5)#ํ๋ฒ ๋๋๊ทธ ํ sleep imgs = driver.find_elements(By.CSS_SELECTOR, 'img.rg_i') os.makedirs(keyword, exist_ok=True) time.sleep(10) for idx, img in enumerate(imgs): # print(idx,img.get_attribute('src')) imgUrl = img.get_attribute('src') if imgUrl == None: break imgName = f'./{keyword}/{keyword+str(idx)}.jpg' urllib.request.urlretrieve(imgUrl, imgName)