Skip to content

Instantly share code, notes, and snippets.

@pn11
Last active August 30, 2020 04:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pn11/acf4d75bd2e995690e9df4139d223d51 to your computer and use it in GitHub Desktop.
Save pn11/acf4d75bd2e995690e9df4139d223d51 to your computer and use it in GitHub Desktop.
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