Skip to content

Instantly share code, notes, and snippets.

@20chan
Last active February 17, 2017 17:14
Show Gist options
  • Save 20chan/aefc1d242fd91ea38765130f50351fa4 to your computer and use it in GitHub Desktop.
Save 20chan/aefc1d242fd91ea38765130f50351fa4 to your computer and use it in GitHub Desktop.
단부루 크롤링 후 사이즈 자동 변환
import json
import urllib.request
from typing import Generator
def pages(limit: int = 10, page: int = 1) -> Generator:
cur = page
while True:
url = 'https://danbooru.donmai.us/posts.json?limit={}&page={}'.format(limit, cur)
res = json.loads(urllib.request.urlopen(url).read().decode('utf-8'))
for post in res:
yield post
cur += 1
p = pages(limit=100)
while True:
post = next(p)
if 'file_url' in post.keys():
if post['rating'] == 'e':
loc = 'Download\\{}.jpg'.format(post['id'])
print('downloading {} in {}...'.format(post['id'], loc))
urllib.request.urlretrieve('https://danbooru.donmai.us{}'.format(post['file_url']), loc)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment