Max_images not working in search_images_ddg() function

unable to control the maximum urls. It’s always returning 100 urls. I am using this function:

def search_images_ddg(term, max_images=200):
    "Search for `term` with DuckDuckGo and return a unique urls of about `max_images` images"
    assert max_images<1000
    url = ''
    res = urlread(url,data={'q':term})
    searchObj ='vqd=([\d-]+)\&', res)
    assert searchObj
    requestUrl = url + 'i.js'
    params = dict(l='us-en', o='json', q=term,, f=',,,', p='1', v7exp='a')
    urls,data = set(),{'next':1}
    while len(urls)<max_images and 'next' in data:
            data = urljson(requestUrl,data=params)
            requestUrl = url + data['next']
        except (URLError,HTTPError): pass
    return L(urls)

Had issues in search_images_ddg() function earlier too (Getting error while downloading images using API)

1 Like

I too have this exact issue. tried with different figures. always gives 100 URLs.

same here.


from fastbook import *
results = search_images_ddg('grizzly bear', max_images=2)

Should be fixed now.