"search_images_ddg" not fetching urls

The code below gives the following output:

(#200) [None,None,None,None,None,None,None,None,None,None...]

Why is the function not fetching the URLS properly?

#hide
! [ -e /content ] && pip install -Uqq fastbook
import fastbook
fastbook.setup_book()

#hide
from fastbook import *
from fastai.vision.widgets import *

results = search_images_ddg('grizzly bear')
ims = results.attrgot('contentUrl')

ims

Hey @nashern,

change your line 'ims = results.attrgot(‘contentUrl’) just to ‘ims = results’ as the search_images_ddg() method returns the urls directly.

Checkout the source code: fastbook/utils.py at master · fastai/fastbook · GitHub

You can see that it returns the urls directly, I think the api is slightly different than the bing search method that was there previously. The attrgot method from fastcore returns a new ‘L’ objects that safely defaults to None if it doesn’t grab an object if I’ve read the source correctly: fastcore - Foundation

So your results object is actually already what you’re looking for, take away the .attrgot() call and you should be good to go, hope that helps!

1 Like