Skip to content

Instantly share code, notes, and snippets.

@luxu
Created February 11, 2019 15:16
Show Gist options
  • Save luxu/c6c663746a537853f07c8bb1280646c2 to your computer and use it in GitHub Desktop.
Save luxu/c6c663746a537853f07c8bb1280646c2 to your computer and use it in GitHub Desktop.
from requests import get
from bs4 import BeautifulSoup as bs
from shutil import copyfileobj
import os
html = get('http://www.afterfest.com.br/mr-moo-4a-edicao/')
soup = bs(html.content, 'html.parser')
def download_file(name, url, pasta):
os.makedirs(pasta, exist_ok=True) # armazena as na pasta
xpto = get(url, stream=True)
with open(u'{}/{}'.format(pasta,name), 'wb') as f:
copyfileobj(xpto.raw, f)
images = [i.a['href'] for i in soup.findAll('div', class_="thumbnail-image")]
for image in images[2:10]:
_image = image.split('/')
name = image.split('/')[-1]
pasta = u'_'.join([_image[4],_image[5],_image[6]])
print(name)
download_file(name, image, pasta)
print(len(images))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment