Last active
January 3, 2016 07:29
-
-
Save kvchen/8429643 to your computer and use it in GitHub Desktop.
scraper for facet.la
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import requests | |
import shutil | |
from bs4 import BeautifulSoup | |
BASE_URL = "http://www.facet.la/wallpapers/" | |
r = requests.get(BASE_URL) | |
soup = BeautifulSoup(r.text) | |
# Loop through all images on the base thumbnail site | |
for thumb in soup.find_all("div", {"class" : "thumb-image"}): | |
# Follow each link and find the wallpaper url | |
img = requests.get(thumb.find("a")["href"]) | |
s = BeautifulSoup(img.text) | |
wp_url = s.find("div", {"id" : "facet-image"}).find("img")["src"] | |
# Name our image | |
wp_name = wp_url.split('/')[-1] | |
print("Downloading {0}".format(wp_name)) | |
# Download the image | |
response = requests.get(wp_url, stream=True) | |
with open(wp_name, 'wb') as out_file: | |
shutil.copyfileobj(response.raw, out_file) | |
del response |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment