-
Notifications
You must be signed in to change notification settings - Fork 11
/
store_functions.py
245 lines (189 loc) · 6.32 KB
/
store_functions.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
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
from re import sub
from re import compile as recompile
import os
JUMIA_BASE_URL = os.getenv('JUMIA_BASE_URL', 'https://www.jumia.com.ng')
KONGA_BASE_URL = os.getenv('KONGA_BASE_URL', 'https://konga.com')
KARA_BASE_URL = os.getenv('KARA_BASE_URL', 'http://www.kara.com.ng')
SLOT_BASE_URL = os.getenv('SLOT_BASE_URL', 'https://slot.ng')
JIJI_BASE_URL = os.getenv('JIJI_BASE_URL', 'https://jiji.ng')
def parse_title_jumia(soup):
'''
Returns list of titles of products from store
'''
titles = soup.find_all("span", class_="name")
titles[:] = [title.get_text() for title in titles]
return titles
def latest_title_jumia(soup):
'''
Returns list of titles of products from store
'''
titles = soup.find_all("span", class_="name")
titles[:] = [title.get_text() for title in titles]
return titles
def parse_title_konga(soup):
'''
Returns list of titles of products from store
'''
titles = []
titles[:] = [product['name'] for product in soup]
return titles
def parse_title_kara(soup):
'''
Returns list of titles of products from store
'''
titles = soup.find_all("h2", class_="product-name")
titles[:] = [title.a.get('title') for title in titles]
return titles
def parse_title_slot(soup):
'''
Returns list of titles of products from store
'''
titles = soup.find_all(class_="mf-product-details-hover")
titles[:] = [title.h2.get_text() for title in titles]
return titles
def parse_title_jiji(soup):
'''
Returns list of titles of products from store
'''
titles=soup.find_all("h4", class_="qa-advert-title b-list-advert__item-title")
titles[:]=[title.get_text().replace('\n', '').strip() for title in titles]
return titles
def parse_image_jumia(soup):
'''
Returns list of images of products from store
'''
images = soup.find_all("div", class_="image-wrapper")
images[:] = [image.img.get('data-src') for image in images]
return images
def parse_image_konga(soup):
'''
Returns list of images of products from store
'''
images = []
images[:] = ["https://www-konga-com-res.cloudinary.com/w_auto,f_auto,fl_lossy,dpr_auto,q_auto/media/catalog/product" + product['image_thumbnail_path'] for product in soup]
return images
def parse_image_kara(soup):
'''
Returns list of images of products from store
'''
images = soup.find_all("a", class_="product-image")
images[:] = [image.img.get('src') for image in images]
return images
def parse_image_slot(soup):
'''
Returns list of images of products from store
'''
images = soup.find_all(class_="mf-product-thumbnail")
images[:] = [image.a.img.get('data-original') for image in images]
return images
def parse_image_jiji(soup):
'''
Returns list of images urls of products from store
'''
images=soup.find_all("a", class_="b-list-advert__item-image js-handle-click-ctr")
images[:]=[image.img.get("data-src") for image in images]
return images
def parse_price_jumia(soup):
'''
Returns list of images of products from store
'''
prices = soup.find_all("span", class_="price-box ri")
prices[:] = [price.span.find("span", dir="ltr").get('data-price') for price in prices]
return prices
def parse_price_konga(soup):
'''
Returns list of prices of products from store
'''
prices = []
prices[:] = [product['special_price'] for product in soup]
return prices
def parse_price_kara(soup):
'''
Returns list of prices of products from store
'''
prices = soup.select(".regular-price,.special-price")
#prices = soup.find_all("span", class_="price")
prices[:] = [ sub(r'[^\d.]', '', price.get_text()) for price in prices]
return prices
def parse_price_slot(soup):
'''
Returns list of prices of products from store
'''
prices = soup.find_all('span', class_="woocommerce-Price-amount amount")
prices[:] = [sub(r'[^\d.]', '', price.get_text()) for price in prices]
return prices
def parse_price_jiji(soup):
'''
Returns list of prices of products from store
'''
prices=soup.find_all(class_="b-list-advert__item-price")
prices[:] = [sub(r'[^\d.]', '', price.get_text()) for price in prices]
return prices
def parse_url_jumia(soup):
'''
Returns list of images of products from store
'''
urls = soup.find_all("div", class_="sku -gallery")
urls[:] = [url.a.get('href') for url in urls]
return urls
def parse_url_konga(soup):
'''
Returns list of urls of products from store
'''
urls = []
urls[:] = ["https://www.konga.com/product/" + product['url_key'] for product in soup]
return urls
def parse_url_kara(soup):
'''
Returns list of urls of products from store
'''
urls = soup.find_all("h2", class_="product-name")
urls[:] = [ url.a.get('href') for url in urls]
return urls
def parse_url_slot(soup):
'''
Returns list of urls of products from store
'''
urls = soup.find_all('div', class_="mf-product-thumbnail")
urls[:] = [url.a.get('href') for url in urls]
return urls
def parse_url_jiji(soup):
'''
Returns list of urls of products from store
'''
urls=soup.find_all('a',class_="b-list-advert__item-textblock js-handle-click-ctr")
urls[:]=[url.get("href") for url in urls]
return urls
#def parse_page_jumia(soup):
'''
Returns jumia page with absolute urls for styles and images
'''
# return soup
#def parse_page_konga(soup):
'''
Returns konga page with absolute urls for styles and images
'''
# links = soup.find_all('link')
# scripts = soup.find_all('script')
# for div in soup.find_all("div", {'class':'newsletter-popup-container js-newsletter-subscription-popup'}):
# div.decompose()
# for link in links:
# link['href'] = urljoin(KONGA_BASE_URL,link.get('href'))
# for script in scripts:
# script['src'] = urljoin(KONGA_BASE_URL,script.get('src'))
# return soup
#def parse_page_kara(soup):
'''
Returns kara page with absolute urls for styles and images
'''
# return soup
#def parse_page_slot(soup):
'''
Returns kara page with absolute urls for styles and images
'''
# return soup
#def parse_page_jiji(soup):
'''
Returns jiji page with absolute urls for styles and images
'''
# return soup