forked from jg-fisher/theModelBot
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathget-models.py
More file actions
44 lines (30 loc) · 854 Bytes
/
get-models.py
File metadata and controls
44 lines (30 loc) · 854 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# model scraping for themodelbot
import requests
from bs4 import BeautifulSoup as bs
import os
# website with model images
url = 'https://www.pexels.com/search/model/'
# 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