-
Notifications
You must be signed in to change notification settings - Fork 0
/
pars_wb.py
128 lines (112 loc) · 5.23 KB
/
pars_wb.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
import requests
import json
def min_max():
for i in range(1, 3):
headers = {
'Accept': '*/*',
'Accept-Language': 'ru,en;q=0.9',
'Connection': 'keep-alive',
'Origin': 'https://www.wildberries.ru',
'Referer': f'https://www.wildberries.ru/catalog/detyam/shkola/shkolnye-prinadlezhnosti/bumazhnaya-produktsiya?sort=popular&page={i}&xsubject=745',
'Sec-Fetch-Dest': 'empty',
'Sec-Fetch-Mode': 'cors',
'Sec-Fetch-Site': 'cross-site',
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/124.0.0.0 YaBrowser/24.6.0.0 Safari/537.36',
'sec-ch-ua': '"Chromium";v="124", "YaBrowser";v="24.6", "Not-A.Brand";v="99", "Yowser";v="2.5"',
'sec-ch-ua-mobile': '?0',
'sec-ch-ua-platform': '"Windows"',
}
params = {
'ab_testing': 'false',
'appType': '1',
'cat': '130054',
'curr': 'rub',
'dest': '-1255987',
'page': '1',
'sort': 'popular',
'spp': '30',
'xsubject': '745',
}
response = requests.get('https://catalog.wb.ru/catalog/school5/v2/catalog',
params=params,
headers=headers).json()
products = []
cheapest_product = {"price": float("inf")}
most_expensive_product = {"price": 0}
for product in response['data']['products']:
price = product['sizes'][0]['price']['basic'] // 100
if price < cheapest_product["price"]:
cheapest_product = {
"Название": product['name'],
"Описание": product['colors'], # product['imt']['text'][0]
"ID": product['id'],
"Цена": str(product['sizes'][0]['price']['basic'] // 100) + " " + str(
product['sizes'][0]['price']['total'] // 100),
"price": price
}
if price > most_expensive_product["price"]:
most_expensive_product = {
"Название": product['name'],
"Описание": product['colors'], # product['imt']['text'][0]
"ID": product['id'],
"Цена": str(product['sizes'][0]['price']['basic'] // 100) + " " + str(
product['sizes'][0]['price']['total'] // 100),
"price": price
}
products.append(cheapest_product)
products.append(most_expensive_product)
with open("all_products.json", "w", encoding="utf-8") as file:
json.dump(products, file, indent=4, ensure_ascii=False)
def all_results():
for i in range(1, 3):
headers = {
'Accept': '*/*',
'Accept-Language': 'ru,en;q=0.9',
'Connection': 'keep-alive',
'Origin': 'https://www.wildberries.ru',
'Referer': f'https://www.wildberries.ru/catalog/detyam/shkola/shkolnye-prinadlezhnosti/bumazhnaya-produktsiya?sort=popular&page={i}&xsubject=745',
'Sec-Fetch-Dest': 'empty',
'Sec-Fetch-Mode': 'cors',
'Sec-Fetch-Site': 'cross-site',
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/124.0.0.0 YaBrowser/24.6.0.0 Safari/537.36',
'sec-ch-ua': '"Chromium";v="124", "YaBrowser";v="24.6", "Not-A.Brand";v="99", "Yowser";v="2.5"',
'sec-ch-ua-mobile': '?0',
'sec-ch-ua-platform': '"Windows"',
}
params = {
'ab_testing': 'false',
'appType': '1',
'cat': '130054',
'curr': 'rub',
'dest': '-1255987',
'page': '1',
'sort': 'popular',
'spp': '30',
'xsubject': '745',
}
response = requests.get('https://catalog.wb.ru/catalog/school5/v2/catalog',
params=params,
headers=headers).json()
# Достаем имя товара,описание товара,достаем id,
# цену товара(со скидкой и без скидки)
products = []
for product in response['data']['products']:
products.append({
"Название": product['name'],
"Описание": product['colors'],
"ID": product['id'],
"Цена без скидки": str(product['sizes'][0]['price']['basic'] // 100),
"Цена со скидкой": str(product['sizes'][0]['price']['total'] // 100)
})
with open("min_max.json", "w", encoding="utf-8") as file:
json.dump(products, file, indent=4, ensure_ascii=False)
def main():
print('1--Получить дорогой товар/дешевый товар')
print('2--Получить все товары')
count = int(input("Введите число для получениия резултата: "))
if count == 1:
min_max()
if count == 2:
all_results()
if __name__ == "__main__":
main()