Skip to content

Instantly share code, notes, and snippets.

@SergProduction
Last active November 7, 2016 11:57
Show Gist options
  • Save SergProduction/49e3d96feb1d6eaf182bb42714764c5e to your computer and use it in GitHub Desktop.
Save SergProduction/49e3d96feb1d6eaf182bb42714764c5e to your computer and use it in GitHub Desktop.
go to link http://electropara.ru/catalog/lampy/, 2.copy code 3.paste in console -> enter. 4. write in console start() -> enter
"use strict";function exportTableToCSV(t,e){function n(t){return t.get().join(l).split(l).join(f).split(d).join(c)}function o(t,e){var n=$(e),o=n.find("td");return o.length||(o=n.find("th")),o.map(a).get().join(d)}function a(t,e){var n=$(e),o=n.text();return o.replace('"','""')}var r=t.find("tr:has(th)"),i=t.find("tr:has(td)"),d=String.fromCharCode(11),l=String.fromCharCode(0),c='";"',f='"\r\n"',h='"';h+=n(r.map(o)),h+=f,h+=n(i.map(o))+'"';var s="data:application/csv;charset=utf-8,"+encodeURIComponent(h);return{name:e+".csv",href:s}}function stop(){_$stop=!0}function start(){function t(e){function o(o){if("ready"==o){var r=exportTableToCSV($(a[e].document).find("#dvData table"),n[e].name);n[e].tag.href=r.href,n[e].tag.setAttribute("download",r.name),n[e].tag.style.color="green",t(e+1)}else n[e].procent.textContent=o+"%",console.log(o)}_$stop||e>=n.length||(a[e]=window.open(n[e].link,n[e].name,"width=600,height=600,scrollbars=yes,resizable=yes,"),a[e].onload=function(){parsePage(a[e],o)})}var e=new Date;e=String(e.getMonth())+String(e.getDate())<=913;var n=[];$("p.title_1 a").each(function(t,e){var o=$(e).html().match(/[А-Я0-9_]+/gim);o=2==o.length?o[0]+"_"+o[1]:o[0];var a=$(e).attr("href");n.push({link:a,name:o})});var o=window.open("about:blank","start","width=600,height=600,scrollbars=yes,resizable=yes,"),a={};n.forEach(function(t){var e=o.document.createElement("p"),n=o.document.createElement("span"),a=o.document.createElement("a");a.href="#",a.textContent=t.name,n.style.margin="0 30px",n.textContent="0%",t.tag=a,t.procent=n,e.appendChild(n),e.appendChild(a),o.document.body.appendChild(e)}),e?t(0):o.document.body.innerHTML='<h1 style="color:green">Пробная версия закончилась =)</h1>'}function parsePage(t,e){function n(t){var e=$(t.document).find("#show_more_all").attr("data-url");return e?(e=e.replace("total=","total=all"),void $.get(e,function(e){$(t.document).find("#my_categories").html(e)}).done(function(){console.log("show_more_all second success")}).fail(function(){console.log("show_more_all error")}).always(function(){console.log("show_more_all finished"),t.parse1lvl()})):void t.parse1lvl()}t.div=document.createElement("div"),t.global=[],t.row_head,t.createTableProgress=function(){t.document.write("START"),t.document.body.innerHTML='\n <div id="preloader">\n <div style="box-sizing: border-box; border: 1px solid #d4df28; width: 100%; height: 30px; padding: 5px; margin: 10px 0;">\n <div id="precont" style="height: 100%; width: 0%; background-color: #3c4247; color: #fff; text-align: center;"></div>\n </div>\n </div>\n <div id="dvData">\n <table border="1" cellpadding="0" cellspacing="0">\n <tr></tr>\n </table>\n </div>\n <a href="" id="export"></a>'},t.parse1lvl=function(){$(t.document).find(".item").each(function(e,n){var o={};o.link=$(n).find("a:eq(2)").attr("href"),o.name=$(n).find("a:eq(2)").html(),o.id=$(n).find("p b").html(),o.link&&t.global.push(o)}),t.createTableProgress(),t.parse2lvl(0)},t.parse2lvl=function(e){$.get(t.global[e].link).done(function(){}).fail(function(){t.document.write("<p>counter "+e+" error</p>")}).always(function(n){t.document.write("<p>counter "+e+" finished</p>"),t.div.innerHTML=n,t.global[e].description=$(t.div).find(".model-description-text p").html(),t.global[e].detail=[],t.global[e].price=$(t.div).find("meta[itemprop]").attr("content");for(var o=$(t.div).find(".model-characteristics-full").find("tr").find(".sp-qest").length,a=0;a<o;a++){var r=$(t.div).find(".model-characteristics-full").find("tr").find(".sp-qest")[a].textContent,i=$(t.div).find(".model-characteristics-full").find("tr").find("td")[a].textContent;t.global[e].detail.push([r,i])}e+=1,e<t.global.length?(t.preloader(e),t.parse2lvl(e)):e==t.global.length&&(t.preloader(e),t.document.write("END"))})},t.preloader=function(n){var o=t.global.length/100;o=n/o;var a=t.document.getElementById("precont");a.style.width=o.toFixed(1)+"%",a.innerHTML=o.toFixed(1)+"%",e&&e(o.toFixed(1)),100==o&&(t.row_head=t.initHeadRow(),t.drawTableHeadRow($(t.document.body).find("#dvData>table"),t.row_head),t.drawTableBodyRow($(t.document.body).find("#dvData>table"),t.global))},t.initHeadRow=function(){var e=t.global[0].detail.map(function(t){return t[0]});return t.global.forEach(function(t){t.detail.forEach(function(t){var n=e.filter(function(e){return e==t[0]}).length;n||(e.push(t[0]),console.log("NO row_head",t[0]))})}),e},t.drawTableHeadRow=function(t,e){$(t).find("tr:eq(0)").append("<th>Название</th>\n<th>Артикул</th>\n<th>Цена</th>\n<th>Описание</th>"),e.forEach(function(e){$(t).find("tr:eq(0)").append("<th>"+e+"</th>")})},t.drawTableBodyRow=function(n,o){var a,r=[];o.forEach(function(e){a="<tr><td>"+e.name+"</td>\n<td>"+e.id+"</td>\n<td>"+e.price+"</td>\n<td>"+e.description+"</td>",r.length=t.row_head.length,e.detail.forEach(function(e,n){t.row_head.forEach(function(t,n){t==e[0]&&r.splice(n,1,e[1])})});for(var o=0;o<r.length;o++)a+="<td>"+r[o]+"</td>";r=[],a+="</tr>",$(n).append(a)}),e("ready")},n(t)}var _$stop=!1;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment