Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import requests
- from bs4 import BeautifulSoup as bs
- import os
- # website with model images
- url = 'https://www.pexels.com/search/new%20york/'
- # download page for parsing
- page = requests.get(url)
- soup = bs(page.text, 'html.parser')
- # locate all elements with image tag
- image_tags = soup.findAll('img')
- # create directory for model images
- if not os.path.exists('models'):
- os.makedirs('models')
- # move to new directory
- os.chdir('models')
- # image file name variable
- x = 0
- # writing images
- for image in image_tags:
- try:
- url = image['src']
- response = requests.get(url)
- if response.status_code == 200:
- with open('model-' + str(x) + '.jpg', 'wb') as f:
- f.write(requests.get(url).content)
- f.close()
- x += 1
- except:
- pass
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement