pythonCopy Codeimport reimport osimport requestsfrom urllibparse import quotedef download_pickeyword num=10 url_template = httpsimagebaiducomsearchacjsontn=resultjson_com&ipn=rj&ct=201326592&fp=res
This is a Python script that downloads images of a specified keyword from Baidu Image Search. It uses the requests library to send HTTP requests to the Baidu Image Search API, and then uses regular expressions to extract the image URLs from the API response. It then downloads the images using the requests library and saves them to a folder on the local machine.
The script takes two arguments: the keyword to search for and the number of images to download (default is 10). It first constructs the API URL using the keyword and page number, and then sends a GET request to the API using the requests library. It then extracts the image URLs from the API response using regular expressions. It then creates a folder on the local machine using the keyword as the folder name, and then downloads each image to the folder using the requests library.
The script is useful for downloading large numbers of images for training machine learning models or for data analysis. However, it is important to respect the terms of service of the API and not abuse the service by downloading too many images too quickly
原文地址: https://www.cveoy.top/t/topic/d4uN 著作权归作者所有。请勿转载和采集!