igorsimb / mp-monitor

Django app for scraping Wildberries
1 stars 0 forks source link

Check if it's possible to check item availability via API (w/o Selenium) #41

Closed igorsimb closed 9 months ago

igorsimb commented 10 months ago

Currently sizes -> stocks always returns an empty list, even though visually (Instepct -> Network tab in Chrome) it's not empty, e.g.

size name: [{'name': '40-42', 'origName': 'XS', 'rank': 254031, 'optionId': 291907516, 'returnCost': 0, 'stocks': []}, {'name': '42-44', 'origName': 'S', 'rank': 280031, 'optionId': 291907517, 're
turnCost': 0, 'stocks': []}, {'name': '44-46', 'origName': 'M', 'rank': 306522, 'optionId': 291907518, 'returnCost': 0, 'stocks': []}, {'name': '46-48', 'origName': 'L', 'rank': 334044, 'optionId': 29190
7519, 'returnCost': 0, 'stocks': []}, {'name': '48-50', 'origName': 'XL', 'rank': 355854, 'optionId': 291907520, 'returnCost': 0, 'stocks': []}, {'name': '50-54', 'origName': '2XL', 'rank': 380662, 'opti
onId': 291907521, 'returnCost': 0, 'stocks': []}, {'name': '54-56', 'origName': '3XL', 'rank': 411098, 'optionId': 291907522, 'returnCost': 0, 'stocks': []}]
size={'name': '40-42', 'origName': 'XS', 'rank': 254031, 'optionId': 291907516, 'returnCost': 0, 'stocks': []}

It looks like JavaScript is used to load the stocks dynamically, and it may be impossible to do it without Selenium. Some theories used:

Maybe the only way to check for availability is via scrape_live_price(sku) function.

igorsimb commented 9 months ago

It turns out you need to specify the region in the request in order to get the item availability information, e.g. dest=-455203 (I think it's Moscow). The url would like this this: https://card.wb.ru/cards/detail?appType=1&curr=rub&dest=-455203&nm={sku}