Skip to content

Instantly share code, notes, and snippets.

@pn11
Last active Aug 30, 2020
Embed
What would you like to do?
Download images from a website. keywords: scraping, requests, python
import requests
import time
from tqdm import tqdm
base_url = 'http://xxxxx.xxx/{image_id}.jpg'
def get_image(image_id):
r = requests.get(base_url.format(image_id=image_id))
with open(f"{image_id}.jpg", 'wb') as f:
f.write(r.content)
time.sleep(1.0)
if __name__ == '__main__':
for i in tqdm(range(1, 100)):
get_image(i)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment