garyfeng / google-images-download

Python Script to download hundreds of images from 'Google Images'. It is a ready-to-run code!
MIT License
1 stars 0 forks source link

similar_images tag no longer works #9

Open garyfeng opened 2 years ago

garyfeng commented 2 years ago

The current similar_images tag composes google image search URL like the following:

                searchUrl = 'https://www.google.com/searchbyimage?site=search&sa=X&image_url=' + similar_images
                headers = {}
                headers[
                    'User-Agent'] = "Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2228.0 Safari/537.36"

                req1 = urllib.request.Request(searchUrl, headers=headers)
                resp1 = urllib.request.urlopen(req1)
                content = str(resp1.read())
                l1 = content.find('AMhZZ')
                l2 = content.find('&', l1)
                urll = content[l1:l2]

                newurl = "https://www.google.com/search?tbs=sbi:" + urll + "&site=search&sa=X"
                req2 = urllib.request.Request(newurl, headers=headers)
                resp2 = urllib.request.urlopen(req2)
                l3 = content.find('/search?sa=X&q=')
                l4 = content.find(';', l3 + 19)
                urll2 = content[l3 + 19:l4]```
                return urll2

This has stopped working. It looks like the URL urll2 now contains some XML fragment, suggesting this two-part process no longer works.