Before I start asking questions, I apologize that I'm a Korean high school student so my questions can be hard to read.
I want my code to print src of image, but It prints None when i is over 22 so I can't download image as many as I want.
It prints like this. This is image src when I insert keyword 'cat'.
23 None
24 None
25 None
26 None
I searched google for about hour but I couldn't find error(bug?) of this That's why I make a question on stackoverflow for the first time
I skipped function named make_dir
import os
import shutil
import urllib.request
import time
from selenium import webdriver
def crawl(keyword, max_count):
cnt = 0
url = "https://www.google.co.in/search?q=" + keyword + "&tbm=isch" # google search url with search word
browser = webdriver.Chrome("C:\\Users\\Master\\Desktop\\crawling\\chromedriver.exe") # webdriver
browser.get(url) # open web page
img_list = browser.find_elements_by_class_name("rg_ic") # find image
for i, el in enumerate(img_list):
if cnt >= max_count:
break
img = img_list[i]
src = img.get_attribute('src')
if src is None:
print(i, src) # img_list includes None so I need to fix it
continue
cnt += 1
print(i, src) # print src
urllib.request.urlretrieve(src, str(cnt) + ".png") # download image
browser.quit()
if __name__ == "__main__":
max_count = int(input("Number of crawls : "))
keyword = input("Search word : ")
make_dir()
crawl(keyword, max_count)
I made code to print src. It prints src until i is 23 but when it over 22, these print only None I want to make them print right src
23 None
24 None
25 None
26 None