用python从google下载随机图片

问题描述 投票:0回答:1

如何下载随机1000张图片 https:/images.google.com。 请帮帮我

python image web-crawler google-crawlers
1个回答
0
投票
from google_images_download import google_images_download  

response = google_images_download.googleimagesdownload()  

search_queries = 
[ 

'The smartphone also features an in display fingerprint sensor.', 
'The pop up selfie camera is placed aligning with the rear cameras.', 
'''In terms of storage Vivo V15 Pro could offer 
   up to 6GB of RAM and 128GB of onboard storage.''', 
'The smartphone could be fuelled by a 3 700mAh battery.', 
] 


def downloadimages(query): 
    arguments = {"keywords": query, 
                 "format": "jpg", 
                 "limit":4, 
                 "print_urls":True, 
                 "size": "medium", 
                 "aspect_ratio":"panoramic"} 
    try: 
        response.download(arguments) 

    except FileNotFoundError:  
        arguments = {"keywords": query, 
                     "format": "jpg", 
                     "limit":4, 
                     "print_urls":True,  
                     "size": "medium"} 

        try: 
            response.download(arguments)  
        except: 
            pass

for query in search_queries: 
    downloadimages(query)  
    print()  

你可以使用google_images_download模块。

© www.soinside.com 2019 - 2024. All rights reserved.