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.
Here is a simple Python script to monitor network traffic. import psutil def monitor_network(): #…
Here's a basic example of web scraping in Python using the requests and BeautifulSoup libraries:…
Here's an example of how you can use Python to SSH into a remote server…
Here's an example of a Python class that represents a rectangle: class Rectangle: def __init__(self,…
Here is a simple Python script that interacts with Active Directory (AD) using the pyad…
Here's a Python script to monitor disk usage on a system and send an email…