Skip to content

Instantly share code, notes, and snippets.

@millionfor
Last active November 2, 2021 01:33
Show Gist options
  • Save millionfor/0d0f35c6bc16d5535138fca1e5b3ef45 to your computer and use it in GitHub Desktop.
Save millionfor/0d0f35c6bc16d5535138fca1e5b3ef45 to your computer and use it in GitHub Desktop.
import requests
import json
import os
down_path = 'images'
if not os.path.exists(down_path):
os.makedirs(down_path)
url = 'http://www.quanquansy.com/data.json'
try:
res = requests.get(url=url)
res.raise_for_status()
except Exception as e:
print(e)
else:
# print(res.text)
json_data = json.loads(res.text)
for i in json_data:
try:
img_url = i['url']
img_suffix = img_url.split('.')[-1]
img_name = i['name']
img_id = i['id']
img_res = requests.get(url = i['url'])
except Exception as e:
print(e)
else:
img = img_res.content
with open(f'./images/{img_name}__{img_id}.{img_suffix}', 'wb') as f:
f.write(img)
print(f'saved! --- {img_name}')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment