-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlushBestSellersAll.py
214 lines (168 loc) · 6.99 KB
/
lushBestSellersAll.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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Sat Jan 2 15:07:55 2021
@author: crystalhansen
scrape site for best sellers and follow the link for the product and its content
captures 'best sellers' strategy and gets the ingredients to make a version of
use best sellers as learning of customers likes and test if changes over time.
Also is granular and finds the best sellers of the subcategories that have per category type.
use for analysis on cross-category interests.
how often does this change?
"""
import bs4 as bs #beautifulSoup
import urllib.request
from datetime import datetime, timedelta
dt = datetime.now() #+ timedelta(hours=1) #sadds an hour for a condition of time is less than one hour ahead
d = dt.strftime("%m-%d-%Y_%H-%M-%S")
print('BestSellers full link following')
#BEST SELLERS
#swiper-wrapper swiper-wrapper
#product-tiles
#product
lushUrl="https://www.lush.ca/en/face/face/"
#has best sellers
#section-swiper
#swiper-container
#swiper-wrapper
#product-tiles swiper-slide swiper
#product
# this has all the individual top level information get the link to get the ingredients
response= requests.get(lushUrl)
lushSoup = BeautifulSoup(response.text,'lxml')
fileName = "lush/face/products/bestSellers_"+ d +".txt"
f=open(fileName,"w")
for product in lushSoup.find_all( 'div', class_="product"):
#print(product.text.strip())
f.write(product.text.strip() + "\n")
for href in product.find_all('a', class_="link",href=True):
#print(href['href'])
link = href['href']
lushItemURL = websiteBaseUrl + link
#print(lushItemURL)
#follow Link
itemResponse= requests.get(lushItemURL)
lushSoupItem = BeautifulSoup(itemResponse.text,'lxml')
#print(lushSoupItem.title.string)
fileName2= "lush/face/products/bestSeller_"+lushSoupItem.title.string + ".txt"
f2=open(fileName2,"w")
f2.write(lushItemURL + "\n")
f2.write(link +"\n")
#get top information section single item page elements
for item in lushSoupItem.find_all('div', class_="product-detail"):
#print(item.text.strip())
f2.write(item.text.strip())
#get item details of single page elements
for itemDetails in lushSoupItem.find_all('div',class_="tab-content"):
# print(itemDetails.text.strip())
f2.write(itemDetails.text.strip())
f2.close()
f.close()
lushUrl="https://www.lush.ca/en/hair/hair/"
#has best sellers
#section-swiper
#swiper-container
#swiper-wrapper
#product-tiles swiper-slide swiper
#product
# this has all the individual top level information get the link to get the ingredients
response= requests.get(lushUrl)
lushSoup = BeautifulSoup(response.text,'lxml')
fileName = "lush/hair/products/bestSellers_"+ d +".txt"
f=open(fileName,"w")
for product in lushSoup.find_all( 'div', class_="product"):
#print(product.text.strip())
f.write(product.text.strip() + "\n")
for href in product.find_all('a', class_="link",href=True):
#print(href['href'])
link = href['href']
lushItemURL = websiteBaseUrl + link
#print(lushItemURL)
#follow Link
itemResponse= requests.get(lushItemURL)
lushSoupItem = BeautifulSoup(itemResponse.text,'lxml')
#print(lushSoupItem.title.string)
fileName2= "lush/hair/products/bestSeller_"+lushSoupItem.title.string + ".txt"
f2=open(fileName2,"w")
f2.write(lushItemURL + "\n")
f2.write(link +"\n")
#get top information section single item page elements
for item in lushSoupItem.find_all('div', class_="product-detail"):
#print(item.text.strip())
f2.write(item.text.strip())
#get item details of single page elements
for itemDetails in lushSoupItem.find_all('div',class_="tab-content"):
# print(itemDetails.text.strip())
f2.write(itemDetails.text.strip())
f2.close()
f.close()
lushUrl="https://www.lush.ca/en/body/body/"
#has best sellers
#section-swiper
#swiper-container
#swiper-wrapper
#product-tiles swiper-slide swiper
#product
# this has all the individual top level information get the link to get the ingredients
response= requests.get(lushUrl)
lushSoup = BeautifulSoup(response.text,'lxml')
fileName = "lush/body/products/bestSellers_"+ d +".txt"
f=open(fileName,"w")
for product in lushSoup.find_all( 'div', class_="product"):
#print(product.text.strip())
f.write(product.text.strip() + "\n")
for href in product.find_all('a', class_="link",href=True):
#print(href['href'])
link = href['href']
lushItemURL = websiteBaseUrl + link
#print(lushItemURL)
#follow Link
itemResponse= requests.get(lushItemURL)
lushSoupItem = BeautifulSoup(itemResponse.text,'lxml')
#print(lushSoupItem.title.string)
fileName2= "lush/body/products/bestSeller_"+lushSoupItem.title.string + ".txt"
f2=open(fileName2,"w")
f2.write(lushItemURL + "\n")
f2.write(link +"\n")
#get top information section single item page elements
for item in lushSoupItem.find_all('div', class_="product-detail"):
#print(item.text.strip())
f2.write(item.text.strip())
#get item details of single page elements
for itemDetails in lushSoupItem.find_all('div',class_="tab-content"):
# print(itemDetails.text.strip())
f2.write(itemDetails.text.strip())
f2.close()
f.close()
lushUrl="https://www.lush.ca/en/discover/bestsellers/?cgid=bestsellers&start=0&sz=28"
#all best sellers
#list of items
response= requests.get(lushUrl)
lushSoup = BeautifulSoup(response.text,'lxml')
fileName = "lush/allBestSellers/allBestSellers_"+ d +".txt"
f=open(fileName,"w")
for product in lushSoup.find_all( 'div', class_="product"):
#print(product.text.strip())
f.write(product.text.strip() + "\n")
for href in product.find_all('a', class_="link",href=True):
#print(href['href'])
link = href['href']
lushItemURL = websiteBaseUrl + link
#print(lushItemURL)
#follow Link
itemResponse= requests.get(lushItemURL)
lushSoupItem = BeautifulSoup(itemResponse.text,'lxml')
#print(lushSoupItem.title.string)
fileName2= "lush/allBestSellers/bestSeller_"+lushSoupItem.title.string + ".txt"
f2=open(fileName2,"w")
f2.write(lushItemURL + "\n")
#get top information section single item page elements
for item in lushSoupItem.find_all('div', class_="product-detail"):
#print(item.text.strip())
f2.write(item.text.strip())
#get item details of single page elements
for itemDetails in lushSoupItem.find_all('div',class_="tab-content"):
#print(itemDetails.text.strip())
f2.write(itemDetails.text.strip())
f2.close()
f.close()