Created
March 10, 2022 07:58
-
-
Save BlackPunk/5d90ec537afee5e1acdf1207b20f5f4a to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const langList = { 'en': 'English'}; | |
| const countryList = { 'gb': 'Great Britain', 'uk': 'United Kingdom', 'ru': 'Russia', | |
| 'fr': 'France', 'es': 'Spain', 'pl': 'Poland'}; | |
| if (input.country) | |
| country(input.country); | |
| close_popup('#collapse', '#collapse'); | |
| close_popup('#Close_X', '#Close_X'); | |
| close_popup('button.close-button', 'button.close-button'); | |
| tag_window_field('data', 'mkorsData'); | |
| tag_window_field('localeCtx', 'localeContextPath'); | |
| tag_all_responses('search', /\/guidedSearch/); | |
| navigate(input.url, {wait_until: 'navigate'}); | |
| wait('#onetrust-accept-btn-handler', {timeout: 5e4}); | |
| click('#onetrust-accept-btn-handler'); | |
| close_popup('#onetrust-accept-btn-handler', '#onetrust-accept-btn-handler'); | |
| wait('.result-container'); | |
| wait('.product-wrapper'); | |
| let p = parse(); | |
| if (p.totalProductCount == 0) | |
| dead_page(`Category ${input.category} not contain products (${input.url})`); | |
| const isLoadingLimit = 3; | |
| let lastChanceFlag = true; | |
| let isLoading = 0; | |
| while (isLoading < isLoadingLimit) { | |
| try { | |
| load_more('.product-wrapper', {children: '.product-tile', timeout: 5000}); | |
| isLoading = 0; | |
| p = parse(); | |
| console.log(`totalProductCount = ${p.totalProductCount}`); | |
| console.log(`loadedProductCount = ${p.loadedProductCount}`); | |
| if ( p.loadedProductCount === p.totalProductCount) | |
| isLoading = isLoadingLimit; | |
| } catch(e) { | |
| p = parse(); | |
| if ( p.loadedProductCount === p.totalProductCount) { | |
| console.log(`totalProductCount = ${p.totalProductCount}`); | |
| console.log(`loadedProductCount = ${p.loadedProductCount}`); | |
| isLoading = isLoadingLimit; | |
| continue; | |
| } | |
| console.log(`loadedProductCount = ${p.loadedProductCount}`); | |
| if ((isLoading == isLoadingLimit-1) && lastChanceFlag) { | |
| lastChanceFlag = false; | |
| isLoading--; | |
| scroll_to('ul.product-wrapper>li:last-child'); | |
| } else | |
| isLoading++; | |
| console.log('----------'); | |
| } | |
| } | |
| wait_for_parser_value('data'); | |
| p = parse(); | |
| let products = []; | |
| let data = p.data; | |
| let search = p.search; | |
| console.log(`p.totalProductCount = ${p.totalProductCount}`); | |
| console.log(`p.loadedProductCount = ${p.loadedProductCount}`); | |
| if (p.loadedProductCount !== p.totalProductCount) { | |
| console.log('!!!! Error while loading products !!!!'); | |
| throw Error('!!!! Error while loading products !!!!'); | |
| } | |
| if (data?.page?.listing?.length) | |
| products = products.concat(data.page.listing); | |
| console.log(`products.length = ${products.length}`); | |
| if (p.totalProductCount > products.length) { | |
| wait_for_parser_value('search'); | |
| search = parse().search; | |
| search = search?.filter(e=>e); | |
| search.forEach(e=>{ | |
| if (e.result.productList) | |
| products = products.concat(e.result.productList); | |
| }); | |
| console.log(`products.length = ${products.length}`); | |
| } | |
| if (products.length !== p.totalProductCount) { | |
| console.log('!!!! Error while loading products !!!!'); | |
| throw Error('!!!! Error while loading products !!!!'); | |
| } | |
| let data_products = []; | |
| products = products.map((e, i)=>{ | |
| let product = {} | |
| let product_colours = [] | |
| let product_url = (new URL(location.href)).origin +`${p.localeCtx ? p.localeCtx : ''}`+ e.productSEOURL; | |
| let price = (e.prices.highListPrice == e.prices.highSalePrice) ? [+e.prices.highSalePrice] : | |
| [+e.prices.highSalePrice, +e.prices.highListPrice]; | |
| price = price.map(l=>l + ' ' + data.page.currencyCode); | |
| if (e.variant_options.colors) { | |
| e.variant_options.colors.forEach((color, i) => { | |
| let url = new URL(product_url); | |
| url.searchParams.set('color', color.colorCode); | |
| product_colours.push({ | |
| name: color.name, | |
| url, | |
| }) | |
| product = { | |
| product_url: url, | |
| product_name: e.SKUs.length ? e.SKUs[0].name : '', | |
| product_price: price, | |
| product_colours, | |
| sequence: { [input.url]: { "1": [ i + 1 ] } }, | |
| root_category: input.root_category, | |
| category: input.category, | |
| category_url: input.url, | |
| language: langList[p.lang], | |
| currency: data.page.currencyCode, | |
| country: countryList[data.page.countryLanguage.replace(/:.*$/, '').toLowerCase()], | |
| }; | |
| data_products.push(product); | |
| }); | |
| } else { | |
| product_colours = []; | |
| product = { | |
| product_url, | |
| product_name: e.SKUs.length ? e.SKUs[0].name : '', | |
| product_price: price, | |
| product_colours, | |
| sequence: { [input.url]: { "1": [ i + 1 ] } }, | |
| root_category: input.root_category, | |
| category: input.category, | |
| category_url: input.url, | |
| language: langList[p.lang], | |
| currency: data.page.currencyCode, | |
| country: countryList[data.page.countryLanguage.replace(/:.*$/, '').toLowerCase()], | |
| }; | |
| } | |
| return product; | |
| }); | |
| data_products.forEach(e=>{ | |
| collect(e); | |
| }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment