I get the error. Exception has occurred: ElementClickInterceptedException Message: element click intercepted: Element <img src= ~~~~~
and I get this Stacktrace: #0 0x5627817c44e3 <unknown> #1 0x5627814f3c76 <unknown> #2 0x5627815359d4 <unknown> #3 0x562781533cbd <unknown> #4 0x562781531d2e <unknown>
my code is
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.by import By
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
import time
import urllib.request
import os
import sys
search = input("검색어: ") # 이미지 이름
count = int(input("download counts: ")) # 크롤링할 이미지 개수
saveurl = "crawled_images/" # 이미지들을 저장할 폴더 주소
path = "crawled_images/" + search + '_' + str(count)
# 중복되는 폴더 명이 없다면 생성
if not os.path.exists(path):
os.makedirs(path)
# 중복된다면 문구 출력 후 프로그램 종료
else:
print('이전에 같은 [검색어, 이미지 수]로 다운로드한 폴더가 존재합니다.')
sys.exit(0)
## 셀레니움으로 구글 이미지 접속 후 이미지 검색
options = webdriver.ChromeOptions()
#options.add_argument("--headless")
options.add_argument("window-size=1920x1080")
service = Service(executable_path='chromedriver')
driver = webdriver.Chrome(service=service, options=options)
#driver = webdriver.Chrome(options=options) #options=options
driver.get("https://www.google.co.kr/imghp?hl=ko&tab=wi&ogbl")
elem = driver.find_element(By.NAME, "q")
elem.send_keys(search)
elem.send_keys(Keys.RETURN)
# 페이지 끝까지 스크롤 내리기
SCROLL_PAUSE_TIME = 1
# 스크롤 깊이 측정하기
last_height = driver.execute_script("return document.body.scrollHeight")
# 스크롤 끝까지 내리기
while True:
driver.execute_script("window.scrollTo(0, document.body.scrollHeight);")
# 페이지 로딩 기다리기
time.sleep(SCROLL_PAUSE_TIME)
# 더 보기 요소 있을 경우 클릭하기
new_height = driver.execute_script("return document.body.scrollHeight")
if new_height == last_height:
try:
driver.find_element(By.CSS_SELECTOR, ".LZ4I").click()
except:
break
last_height = new_height
# 요소가 나타날 때까지 기다림
#wait = WebDriverWait(driver, 10)
#image_ = wait.until(EC.element_to_be_clickable((By.CSS_SELECTOR, ".rg_i.Q4LuWd")))
#image_element.click()
#이미지 찾고 다운받기
images = driver.find_elements(By.CSS_SELECTOR, ".rg_i.Q4LuWd")
count = 1
for image in images:
image.click()
time.sleep(3)
imgUrl = driver.find_element(By.CSS_SELECTOR, ".n3VNCb.KA1RDb").get_attribute("src")
urllib.request.urlretrieve(imgUrl, str(count) + ".jpg")
count = count + 1
#for i in range(count):
# image_element[i].click() # 이미지 클릭
# time.sleep(3)
# imgUrl = driver.find_element(By.CSS_SELECTOR, ".n3VNCb.KA1RDb").get_attribute("src")
# urllib.request.urlretrieve(imgUrl, search + str(i) + ".jpg") # 이미지 다운
driver.close()
So you know annotation(#) I tried many somethings.. but I can't the problem. and when I reslove this error I got the other error. that is image didn't download my 'crawled_images' folder. Actually I checked the everythings. But folder path is good you know, subfolder of 'crawled_images' folder is well created. and chromedriver path, it worked just fine with no problem. if you know about this problem please help me. :)
everything. I tried to reslove this error with my friends GPT.