igorsimb / mp-monitor

Django app for scraping Wildberries
1 stars 0 forks source link

Get price history from WB's API #46

Open igorsimb opened 8 months ago

igorsimb commented 8 months ago

The task is a bit tricky. It turns out you can find price-history.json in the response. The request url looks like this: https://basket-04.wbbasket.ru/vol611/part61105/61105868/info/price-history.json

You get a reponse that looks like this:

[
    {
        "dt": 1689465600,
        "price": {
            "RUB": 138900
        }
    },
    {
        "dt": 1691884800,
        "price": {
            "RUB": 149200
        }
    },
    {
        "dt": 1692489600,
        "price": {
            "RUB": 153900
        }
    },
    {
        "dt": 1693094400,
        "price": {
            "RUB": 148800
        }
    },

dt is likely a timestamp that is in Unix timestamp format, which is a standard way to represent seconds since the Unix epoch (January 1, 1970, 00:00:00 UTC). In this case, the JSON response provides a series of price data points, each associated with a timestamp. Based on this assumption, let's convert this to a human readable format:

[
    {
        "dt": "2023-07-16 00:00:00",
        "price": {
            "RUB": 138900
        }
    },
    {
        "dt": "2023-08-13 00:00:00",
        "price": {
            "RUB": 149200
        }
    },
    {
        "dt": "2023-08-20 00:00:00",
        "price": {
            "RUB": 153900
        }
    },
    {
        "dt": "2023-08-27 00:00:00",
        "price": {
            "RUB": 148800
        }
    }
]

Main caveat

basket, vol and part are different for different items. According to this response:

So we could iterate over baskets, put the correct vol and part and potentially find the correct price-history.json file. AFAIU, the images have very similar structure.