Inspiration

Major League Hacking is my inspiration.

What it does

It scraps cat photos from unsplash.com

How we built it

I built it using Python.


import requests import os

class Unsplash: def init(self,search_term,per_page,quality="thumb"): self.search_term = search_term self.per_page = per_page self.page = 0 self.quality = quality

def set_url(self):
    return f"https://unsplash.com/napi/search/photos?query=(self.search_term)&xp=&per_page=(self.per_page)&page=(self.page)"

def make_request(self):
    url = self.set_url()
    return requests.request("GET",url)

def get_data(self):
    self.data = self.make_request().json()

def save_path(self,name):
    download_dir = "unsplash"
    if not os.path.exists(download_dir):
        os.mkdir(download_dir)

    return f"{os.path.join(os.path.realpath(os.getcwd()),download_dir,name)}.jpg"

def downlaod(self,url,name):
    filepath = self.save_path(name)
    with open(filepath,"wb") as f:
        f.write(requests.request("GET",url).content)

def Scrapper(self,pages):
    for page in range(0,pages+1):
        self.make_request()
        self.get_data()
        for item in self.data['results']:
            name = item['id']
            url = item['urls'][self.quality]
            self.downlaod(url,name)

scrapper = Unsplash("cars",1) scrapper.Scrapper(1)


Challenges we ran into

It was a fun challenge

Accomplishments that we're proud of

Taking this challenge is big accomplishment

What we learned

I learned to program a web scraper

What's next for Web Scraping Application

Probably give it some GUI interface.

Built With

Share this project:

Updates