You can see the ranking of cosmetics on the cosmetics site LIPS. This time I got the eyeshadow ranking, I would like to make a graph with the product name on the vertical axis and the star rating on the horizontal axis. The flow from top to bottom is the ranking.
import requests
from bs4 import BeautifulSoup
import matplotlib.pyplot as plt
#Scraping LIPS site
urlName = "https://lipscosme.com/"
url = requests.get(urlName)
url.raise_for_status()
bs = BeautifulSoup(url.text, "html.parser")
url_list = []
# url_The list contains URLs for eyeshadow, foundation, lipstick, and lotion
#This time, only the eye shadow is graphed
for i in bs.select('a.ranking-products-list__more-link'):
url_list.append(urlName + i.get('href'))
url_list.pop() #Deleted the URL of the lotion
url_list.pop() #Remove lipstick URL
url_list.pop() #Remove foundation URL
name_list = []
start_list = []
for i in url_list:
url_temp = requests.get(i)
url_temp.raise_for_status()
bs_temp = BeautifulSoup(url_temp.text, "html.parser")
for j in bs_temp.select('div.ProductListArticle'):
for k in j.select('div.ProductListArticle__product'):
for k2 in k.select('h2.ProductListArticle__productTitle-productName'):
name_list.append(k2.text)
for k3 in k.select('span.ratingStar__num'):
start_list.append(k3.text)
#Graph creation
#Top 10
start_list = start_list[:10]
name_list = name_list[:10]
#Reverse order to display ranking from top to bottom
start_list.reverse()
name_list.reverse()
labels = [float(i) for i in start_list] #Put a star rating on the label next to it
height = name_list #Put the name of the eyeshadow on the vertical label
fig = plt.figure()
ax = fig.add_subplot(1,1,1)
ax.barh(height,labels,height = 0.5)
plt.xticks(rotation=90)
plt.title('10 eyeshadow rankings', fontsize=15)
plt.ylabel("Cosmetic name", fontsize=15)
plt.xlabel("Star rating", fontsize=15)
plt.tick_params(labelsize=10)
plt.show()
I think that the star rating goes down as you go down from the first place in the ranking. The result was that the stars did not change much.
I hope you can refer to this graph when you buy eyeshadow!
Next time, let's make a graph of foundation and other cosmetics.
Recommended Posts