Instantly share code, notes, and snippets.

What would you like to do?
Python script to download wallpapers from wallhaven.
from bs4 import BeautifulSoup
from itertools import count
import requests
url = ''
jpg = ''
png = ''
status = '\r[page {:0>3}] [image {:0>2}|24] [{:.<24}]'.format
for i in count(1):
soup = BeautifulSoup(requests.get(url + str(i)).text)
figs = soup.find_all('figure')
for j, fig in enumerate(figs, 1):
print status(i, j, j*'#'),
name = fig.find('a').get('href').rsplit('/', 1)[1]
r = requests.get(jpg % name)
if r.status_code == 404:
r = requests.get(png % name)
name += '.png'
name += '.jpg'
with open('%03d-%02d-%s' % (i, j, name), 'wb') as f:
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment