Scripts

Python Script to Download Images from URL

Here is an example Python script that downloads images from a given URL and saves them to a local directory:

import requests

def download_image(url, save_path):
    # Open the image URL
    response = requests.get(url)
    
    # Open the save path
    with open(save_path, 'wb') as f:
        # Write the image data to the save path
        f.write(response.content)

# Example usage
url = "https://images.unsplash.com/photo-1593642532857-b1ebc8e7c147"
save_path = "image.jpg"
download_image(url, save_path)

This script uses the requests library to make a GET request to the image URL, which returns the image data. It then opens a file at the specified save path, and writes the image data to it in binary mode. You can use a loop and a list of urls to download multiple images or use a function to pass the url and save_path as arguments. You can also customize this script to handle errors, such as if the URL is not valid or the image cannot be downloaded for some reason. You can also add file extensions to the save path depending on the type of image you are trying to download.

PyJoy

Recent Posts

Python Script to Monitor Network Traffic

Here is a simple Python script to monitor network traffic. import psutil def monitor_network(): #…

2 years ago

Python Script for Web Scraping

Here's a basic example of web scraping in Python using the requests and BeautifulSoup libraries:…

2 years ago

Python Script to SSH and Run Commands

Here's an example of how you can use Python to SSH into a remote server…

2 years ago

Python Code Example with Classes

Here's an example of a Python class that represents a rectangle: class Rectangle: def __init__(self,…

2 years ago

Python Script Example with Main Method in Active Directory

Here is a simple Python script that interacts with Active Directory (AD) using the pyad…

2 years ago

Python Script Example for System Administrators

Here's a Python script to monitor disk usage on a system and send an email…

2 years ago