Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function onOpen() {
- SpreadsheetApp.getUi().createMenu("🔥")
- .addItem('Загрузить!', 'myFunction')
- .addToUi();
- };
- function myFunction() {
- const url = 'https://card.wb.ru/cards/detail?nm='
- const ss = SpreadsheetApp.getActive()
- const nms = ss.getSheetByName('Что парсим').getDataRange().getValues().filter(d => d[1]).map(d => d[0]).join(";");
- const shTo = ss.getSheetByName('Загруженное');
- var response = UrlFetchApp.fetch(url + nms);
- response = JSON.parse(response);
- var arr = parse(response);
- shTo.clear();
- shTo.getRange(1, 1, arr.length, arr[0].length).setValues(arr);
- };
- function parse(json) {
- const r = json['data']['products'];
- var arr = [];
- for (n in r) {
- const fl = r[n];
- const id = fl?.['id'];
- const name = fl?.['name'];
- const brand = fl?.['brand'];
- const brandId = fl?.['brandId'];
- const priceU = fl?.['priceU'] / 1000;
- const sale_prc = fl?.['sale'];
- const salePriceU = fl?.['salePriceU'] / 1000;
- const pics = fl?.['pics'];
- const rating = fl?.['rating'];
- const feedbacks = fl?.['feedbacks'];
- const volume = fl?.['volume'];
- const colors = fl?.['colors'].map(t => t['name']).join(', ');
- const sizes = fl?.['sizes'];
- for (nn in sizes) {
- const size = sizes[nn];
- const size_name = size['name'];
- const size_origName = size['origName'];
- const stocks = JSON.stringify(size['stocks']);
- arr = arr.concat([[id, name, brand, brandId, priceU, sale_prc, salePriceU, pics, rating, feedbacks, volume, colors, size_name, size_origName, stocks]]);
- };
- };
- return [['id', 'name', 'brand', 'brandId', 'priceU', 'sale_prc', 'salePriceU', 'pics', 'rating', 'feedbacks', 'volume', 'colors', 'size_name', 'size_origName', 'stocks']]
- .concat(arr);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement