-
Notifications
You must be signed in to change notification settings - Fork 0
/
NikeScrapper.py
58 lines (48 loc) · 2.79 KB
/
NikeScrapper.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
import requests
import json
from offer import Offer
class NikeScrapper:
def __init__(self):
self._mens_shoes = 'https://store.nike.com/html-services/gridwallData?country=PL&lang_locale=pl_PL&gridwallPath=mczyni-buty/7puZoi3&pn'
self._mens_cloths = 'https://store.nike.com/html-services/gridwallData?country=PL&lang_locale=pl_PL&gridwallPath=mczyni-odzie/1mdZ7pu&pn'
def find_steals(self):
shop_urls = [self._mens_shoes, self._mens_cloths]
found_steals = []
for products_url in shop_urls:
products_json = json.loads(requests.get(products_url).content)
page = 1
while products_json['foundProductResults']:
for property in products_json['sections']:
for item in property['items']:
if item['inWallContentCard']:
continue
if item['numberOfColors'] > 1:
for color in item['colorways']:
if color['overriddenLocalPrice']:
title = str(item['title'])
title = title.replace("'", "")
title = title.replace(" ", "_")
old_price = int(str(color['localPrice']).split()[0])
new_price = int(str(color['overriddenLocalPrice']).split()[0])
url = str(color['pdpUrl'])
url_image = str(color['imageUrl'])
item_color = str(color['colorDescription'])
offer = Offer(title, url, url_image, new_price, old_price, item_color)
found_steals.append(offer)
# offer.print_offer()
elif color['overriddenLocalPrice']:
title = str(item['title'])
title = title.replace("'", "")
title = title.replace(" ", "_")
old_price = int(str(color['localPrice']).split()[0])
new_price = int(str(color['overriddenLocalPrice']).split()[0])
url = str(item['pdpUrl'])
url_image = str(item['spriteSheet'])
offer = Offer(title, url, url_image, new_price, old_price, item_color)
found_steals.append(offer)
# offer.print_offer()
products_json = json.loads(requests.get(products_url + "=" + str(page)).content)
page += 1
# for i in found_steals:
# print(i.print_offer())
return found_steals