সরাসরি প্রধান সামগ্রীতে চলে যান

Download Pexels Images Using API | Save Any Image with Python | API Guide

 I've found the API of pexels, which might work for a while...
Is it allowed???
Sample code:




Python code

# Install required libraries !pip install requests import os import requests from urllib.parse import urljoin # Create the directory to save images save_dir = "dwnImgs" os.makedirs(save_dir, exist_ok=True) # Function to fetch image data from Pexels API def fetch_images(query, page=1, per_page=10): url = "https://www.pexels.com/en-us/api/v3/search/photos" headers = { "accept": "*/*", "accept-language": "en-BD,en;q=0.9,bn-BD;q=0.8,bn;q=0.7,en-GB;q=0.6,en-US;q=0.5", "authorization": "", "content-type": "application/json", "priority": "u=1, i", "sec-ch-ua": "\"Not/A)Brand\";v=\"8\", \"Chromium\";v=\"126\", \"Google Chrome\";v=\"126\"", "sec-ch-ua-mobile": "?0", "sec-ch-ua-platform": "\"Windows\"", "sec-fetch-dest": "empty", "sec-fetch-mode": "cors", "sec-fetch-site": "same-origin", "secret-key": "I've Intentionally hid it!", } params = { "query": query, "page": page, "per_page": per_page, "orientation": "all", "size": "all", "color": "all", "sort": "popular", "seo_tags": "true" } response = requests.get(url, headers=headers, params=params) if response.status_code == 200: return response.json() else: print(f"Failed to fetch data: {response.status_code} - {response.text}") return None # Function to download images def download_images(data): if not data or "data" not in data: print("No data available to process.") return for item in data["data"]: image_url = item["attributes"]["image"]["download_link"] image_id = item["id"] image_filename = os.path.join(save_dir, f"{image_id}.jpg") # Download the image response = requests.get(image_url, stream=True) if response.status_code == 200: with open(image_filename, "wb") as img_file: img_file.write(response.content) print(f"Saved image: {image_filename}") else: print(f"Failed to download image: {image_url}") # Fetch and download images query = "lawn mower" # Change this query to your desired search term page = 1 per_page = 5 # Number of images per page image_data = fetch_images(query=query, page=page, per_page=per_page) download_images(image_data)




I've successful! Any query you give, any quantity image you want and get it without any hassle!
No need to visit pexels!








মন্তব্যসমূহ

এই ব্লগটি থেকে জনপ্রিয় পোস্টগুলি

Chat GPT Demo

এগুলো ChatGPT Site Auto এর ডেমো... আমার API ও বানানো আছে, যেকোনও ভাবে বানাতে পারব ইনশাআল্লাহ... তবে API এর টা কিছু Human Touch লাগবে আর Site: chat.openai.com দিয়ে যেটা বানানো ওইটা ফোরাম সার্চ করে নিত, তাই ভাল ডাটা থাকে, তেমন edit/human touch লাগে না। শুধু হালকা Human Check দিতে হয় Formatting এর জন্য, তবে মোটামুতটি এই ফরমাটে আসে... Title: mantis tiller 2-stroke vs 4-stroke Introduction Mantis tillers have become a popular choice for gardeners and landscapers alike due to their ability to easily till soil and prepare gardens for planting. However, when it comes to choosing between a 2-stroke or 4-stroke engine, it can be challenging to know which one is the best fit for your needs. In this blog post, we will take a closer look at the differences between these two types of engines and explore their advantages and disadvantages in the context of Mantis tillers. Whether you are a professional landscaper or a homeowner looking to cultivate a beautiful garden, this guide will help you mak...