I keep getting an empty list on the Grizzly Bear project, despite tweaking my code to take into account this prior thread on the subject. Does anyone know what I might be doing wrong?
bear_types = 'grizzly','black','teddy'
path = Path('bears')
if not path.exists():
path.mkdir()
for o in bear_types:
dest = (path/o)
dest.mkdir(exist_ok=True)
results = search_images_ddg(f'{o} bear')
download_images(dest, urls=results.attrgot('contentUrl'))
fns = get_image_files(path)
fns
Have you verified which lines of your code are actually being executed? Its about time I learnt to use the python debugger in jupyter, but in the meantime you can do it the older fashioned way…
if not path.exists():
print("GOT HERE")
path.mkdir()
for o in bear_types:
print("PROCESSING: ", o)
...etc
Code:
if not path.exists():
path.mkdir()
print(path)
for o in bear_types:
print(True)
dest = (path/o)
dest.mkdir(exist_ok=True)
results = search_images_ddg(f’{o} bear’) #Note: changed to search_images_ddg as of the 2022 videos
download_images(dest, urls=results) #Note: updates urls=results.attrgot(‘contentUrl’) => results
How did you go with this? I got pulled back to this thread by another post, and as pointed out by @jjeria and @jdvaugha, attrgot was required with Bing search, but not DDG search.
It seems like you are using ddg_search.
In this case you should use: download_images(dest, urls=results)
instead of: download_images(dest, urls=results.attrgot('contentUrl'))