-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
35 lines (28 loc) · 1.04 KB
/
main.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
import requests
import csv
# Store URL
url_boutique = "https://myjoliecandle.com/"
# Prepare the CSV file
with open('produits.csv', 'w', newline='') as file:
writer = csv.writer(file)
# Header of CSV
writer.writerow(["Nom du Produit", "ID du Produit", "Nom de la Variante", "ID de la Variante", "Prix", "Disponible"])
page = 1
while True:
# Get the data
try:
response = requests.get(f"{url_boutique}/products.json?page={page}")
data = response.json()
except:
print(f'NUMERO DE PAGE >> {page}')
# If no products, break the loop
if not data['products']:
break
# For each product
for product in data['products']:
# Get the variants
for variant in product['variants']:
# Write in the CSV file
writer.writerow([product['title'], product['id'], variant['title'], variant['id'], variant['price'], variant['available']])
# Go the next page
page += 1