-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathfacets_image_scraper.py
35 lines (29 loc) · 1.05 KB
/
facets_image_scraper.py
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
'''
simple yet functional scraper to get wallpapers from facets.la
<3 Justin Maller
'''
import os
import requests
import urllib
from bs4 import BeautifulSoup
def get_images():
try:
page_src = requests.get('http://www.facets.la/wallpapers/')
page_soup = BeautifulSoup(page_src.text, 'html.parser')
for image_link in page_soup.findAll('div', {'class', 'thumb-image'}):
try:
image_url = image_link.find('a').get('href')
image_url_src = requests.get(image_url)
image_url_soup = BeautifulSoup(image_url_src.text, 'html.parser')
img = image_url_soup.find('div', id='facet-wallpaper').find('img').get('src')
title = image_url_soup.find('div', {'class', 'size15'}).find('strong').text
urllib.request.urlretrieve(img, folder_path + '/' + title + '.jpg')
print('Finished downloading ' + title)
except:
pass
except:
print('some error. I\'m just going to ignore it ¯\_(ツ)_/¯')
if __name__ == '__main__':
folder_path = input('Enter a path to store these wallpapers:\n')
os.makedirs(folder_path, exist_ok=False)
get_images()