Difference in images produced in search_images function Vs searching manually

Hey all,
I was going through lesson 1 of the 2022 course,
Would someone pls mind explaining how this function actually searches for images in duckduckgo engine ? When I try to manually search on the search engine using the term I entered in the function, it produces a very conspicuous difference in the images downloaded Vs what I see on the search engine.

def search_images(term, max_images=200):
    url = 'https://duckduckgo.com/'
    res = urlread(url,data={'q':term})
    searchObj = re.search(r'vqd=([\d-]+)\&', res)
    requestUrl = url + 'i.js'
    params = dict(l='us-en', o='json', q=term, vqd=searchObj.group(1), f=',,,', p='1', v7exp='a')
    urls,data = set(),{'next':1}
    while len(urls)<max_images and 'next' in data:
        data = urljson(requestUrl,data=params)
        urls.update(L(data['results']).itemgot('image'))
        requestUrl = url + data['next']
        time.sleep(0.2)
    return L(urls)[:max_images]
urls = search_images('fabric photos', max_images=10)
1 Like

With your manual search, do you append “photos” to your search?
I see different results between:

I used them both, but the top searches that were shown on screen when I searched manually, weren’t same as the ones that were downloaded.

1 Like