Here are just a simple implementation, because time is urgent.
The main problem is that a lot of Taobao product classification, a lot of fight a Add categories too tired to stand.
There is a lot to fight the requirements for each category must have a picture, which is the sum of the pit.
Mainly js achieve
Grab Taobao classification
Get an array of Taobao Category:
var arr = []; $("ul.J_TSaleProp li a span").each(function (index) { var item = $("ul.J_TSaleProp li a span")[index]; var str = $(item).text(); arr.push(str); }); console.log(arr); console.log(JSON.stringify(arr));
Like arrays have been classified:
There is caught html Like this node: <div class = "van-sku-group-container">
var arr = []; $(".van-sku-row__item-name").each(function (index) { var item = $(".van-sku-row__item-name")[index]; var str = $(item).text(); arr.push(str); }); console.log(arr); console.log(JSON.stringify(arr));
Automatically increase a lot to fight Category:
// automatically increase the classification window.myArr = [ "Kerastase Olivia supple shampoo", "Kerastase constant care shampoo No. 1", "Kerastase flexible core machine shampoo", "Kerastase (new slim) roots of special care shampoo" "Kerastase flexible core machine conditioner", "repair conditioner Kerastase tough," "tough repair Kerastase shampoo", "Kerastase delicate hair shampoo for men", "Kerastase new purification dandruff shampoo "" Kerastase soothing moisturizing shampoo "," Kerastase Daisy Plaza shampoo "," Kerastase Daisy Yi soft hair conditioner "," Kerastase brightly lit depth of color protection shampoo "," card Poetry live shampoo new and old random "," Kerastase constant care protein conditioner old and new random "," Kerastase dual function shampoo "," Kerastase scalp soothing wash (overseas counter version), "" shampoo Kerastase when black Diamond condensate "," Kerastase constant care shampoo old and new random number 2 " ]; window.myArrIndex = 0 ; function Fn3 () { the setInterval ( function () { IF (window.myArrIndex> window.myArr.length - 1) { return; } console.log(window.myArrIndex); var div_goods = document.getElementsByClassName("goods-spec-row-box")[0].getElementsByClassName("goods-spec-row-btn")[0]; var input = div_goods.getElementsByClassName("mui-form-group-input")[0]; var btn = div_goods.getElementsByTagName("a")[0]; div_goods.getElementsByClassName("mui-form-group-input")[0].focus(); setTimeout(function () { var strValue = window.myArr[window.myArrIndex]; div_goods.getElementsByClassName("mui-form-group-input")[0].value = strValue; window.myArrIndex = window.myArrIndex + 1; setTimeout(function () { div_goods.getElementsByClassName("mui-form-group-input")[0].blur(); }, 500); }, 500); setTimeout(function () { btn.click(); }, 2000); }, 3000); }
In the fight to achieve a lot of pages of ideas:
In the console to dynamically add html page, html content: Dynamic add a button, the button with the binding events, events every few seconds to add a dynamic classification.
window.myArr = [ "Kerastase Olivia supple shampoo", "Kerastase Lotion 1 constant care shampoo", "Kerastase flexible core machine shampoo", "Kerastase (new slim) roots of special care shampoo", "Kerastase flexible core machine conditioner "," repair conditioner Kerastase tough, "" tough repair Kerastase shampoo "," Kerastase delicate hair shampoo for men "," Kerastase new purification dandruff shampoo "," Kerastase soothing moisturizing shampoo "," Kerastase Daisy Plaza shampoo "," Kerastase Daisy Yi soft hair conditioner "," Kerastase brightly lit depth of color protection shampoo "," card Poetry live shampoo old and new random "," Kerastase nourish the constant protection protein conditioner old and new random "," Kerastase dual function shampoo "," Kerastase scalp soothing wash (overseas counter version), "" shampoo black Diamond condensate Kerastase "," Kerastase constant care shampoo 2 a random number of the new and old " ]; window.myArrIndex = 0 ; var strClick =" " ; strClick div = document.createElement("div"); div.setAttribute('style', 'background-color:red;width:50px;height:50px;position:absolute;left:10px;top:1500px'); var input = document.createElement("input"); input.setAttribute('type', 'button'); input.setAttribute('onclick', strClick); input.value = "click"; div.appendChild(input); document.body.appendChild(div);
Taobao classification download pictures, picture name is the name of the classification:
// method to download images
//https://www.jianshu.com/p/dfe9c351b898 function downloadImgByBlob(url, fileName) { var img = new Image(); img.onload = function () { var canvas = document.createElement('canvas'); canvas.width = img.width; canvas.height = img.height; var ctx = canvas.getContext('2d'); // 将img中的内容画到画布上 ctx.drawImage(img, 0, 0, canvas.width, canvas.height); //The contents of the canvas to convert Blob canvas.toBlob ((BLOB) => { // BLOB Switch homologous URL var blobUrl = window.URL.createObjectURL (BLOB); // Create a link var a = document.createElement ( 'a ' ); a.href = blobUrl; a.download = fileName; // trigger a click event link, the browser to start downloading the file a.click (); }); }; img.src = url; // must be set, otherwise, the contents of the canvas can not be converted into blob img.setAttribute('crossOrigin', 'Anonymous'); }
Achieve code
var arr2 is = []; var index2 = 0 ; // remove all free memory into an array $ ( "Li ul.J_TSaleProp A span") each (. function (index) { var Item = $ ( "Li ul.J_TSaleProp span A " ) [index]; var name = $ (Item) .text (); var . = $ URL (Item) .parent () CSS (" Image-background " ); URL = url.replace ( 'URL ( " ',' ') .replace ('") ',' ' ); arr2.push ({URL: URL, name: name}); }); // click of a button to download a picture function Fn4 () { IF (index2 > (arr2.length - 1)) { return; } var item = arr2[index2]; var url = item.url; url = url.replace("_30x30.jpg", ""); downloadImgByBlob(url, item.name + ".jpg"); index2++; }