-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexample.py
More file actions
35 lines (26 loc) · 1018 Bytes
/
example.py
File metadata and controls
35 lines (26 loc) · 1018 Bytes
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
from __future__ import annotations
import asyncio
from ozon_api.abstraction import OzonPage
from ozon_api.manager import OzonAPI
async def main() -> None:
async def parse(model):
products = model.extract_products()
if not products:
print("Товары не найдены.")
return
for product in products:
print(product.render())
async with OzonAPI(headless=False) as api:
resp = await api.Catalog.feed()
with open("response.json", "w", encoding="utf-8") as f:
import json
f.write(json.dumps(resp.json(), indent=4, ensure_ascii=False))
model = OzonPage.model_validate(resp.json())
await parse(model)
for _i in range(100):
await asyncio.sleep(1)
resp = await api.Catalog.feed(page_url=model.next_page)
model = OzonPage.model_validate(resp.json())
await parse(model)
if __name__ == "__main__":
asyncio.run(main())