Scraping Sephora and a Flask Querying Application
Photo by Eric Wüstenhagen
Introduction
For my scraping project, I decided to scrape product reviews from Sephora's website. Sephora is known as a one stop shop for a person's beauty needs, offering various brands of skincare, makeup, haircare, body and fragrance products at every price point.
The website holds more than 300 brands, at least 5000 products and thousands of reviews. The site was relatively easy to scrape and I was able to finish scraping ahead of schedule. With a lot of time on my hands, I took the opportunity to challenge myself by building a querying application using Flask.
How to Scrape Sephora
There are three page levels that you need to go through to reach the reviews area. First is the brands list page, which contains all the brands. Next is the brand page, where we can see all the products that the brand sells in the website. The product page is last. It includes specific information about the product, as well as its reviews. The reviews were not scraped from the site but were taken from an API which can be accessed by using the product ID.
Scraping the brand names and links is straightforward, with the names wrapped in a tag with class "u-hoverRed u-db u-p1" and the href link within the same location.
The product names, on the other hand, come as a dictionary search result which can be found on the bottom of the brand page's source code. I used Python's re package to get the product link, name, ID and average rating.
It was easier to scrape the total number of reviews from the product page, that's why I decided to go a level deeper, despite already having the information I needed to access the reviews API.
The product ID will then be used to construct the link where we can get the reviews and reviewer information. The link structure can be found in the web browser's Inspect Element in the Network area. After that go to the row named "reviews.json" under the header tab. The API will provide a dictionary which can be digested using the json package. The review text and reviewer's skintype, skintone, haircolor and eyecolor are gathered here. Running my scraping program on 17 brands resulted in the accumulation of more than 80,000 reviews.
Querying Application using Flask
I built a Flask Application that shows the top rated products given the brand or physical trait. I think it is useful to know which products are highly rated for a group of people with specific traits.
The application has three main areas, namely, the inputs, results and plot pages. Instead of detailing l how each page works here, I’d encourage you to try the application out to see for yourself!