// ==UserScript== // @name 阿里巴巴国际站批量下载访客详情关键词 // @namespace http://tampermonkey.net/ // @version 1.0.1 // @description 在访客详情页面,批量营销按钮后面插入一个下载按钮,点击可以从头开始记录每位访客所有的关键词(页面中看到什么关键词就会记录什么关键词),最终输出成csv文件自动下载,可以选择自动去重版本,把“全收集完后可选数组降维和去重”这一行注释下面的代码注释互换就好。 // @author TuffPlusOM // @match http://*/* // @match https://*/* // @grant GM_addStyle // @downloadURL none // ==/UserScript== 'use strict'; var globalAllresult = []; // 将下边代码粘贴到浏览器的控制台 (function(console){ console.save = function(data, filename){ if(!data) { console.error('Console.save: No data found!') return; } if(!filename) filename = 'console.json' if(typeof data === "object"){ data = JSON.stringify(data, undefined, 4) } var blob = new Blob([data], {type: 'text/json'}), e = document.createEvent('MouseEvents'), a = document.createElement('a') a.download = filename a.href = window.URL.createObjectURL(blob) a.dataset.downloadurl = ['text/json', a.download, a.href].join(':') e = new MouseEvent ("click"); //e.initMouseEvent('click', true, false, window, 0, 0, 0, 0, 0, false, false, false, false, 0, null) !!!deprecated!!! a.dispatchEvent(e) } })(console) // 访客详情页关键词收集(打开访客详情页,按F12打开控制台console,直接复制粘贴代码) function collectKeywords(){ var source = document.getElementsByClassName("td-search-keywords align-left"); var temp = []; var result=[]; for (var i = 0; i < source.length; i++) { if(source[i].getElementsByTagName('div')[0]!==undefined){ temp[i] = source[i].getElementsByTagName('div')[0].getAttribute("data-text").match(/
.*?<\/div>/g); for (var t = 0; t < temp[i].length; t++) { var q = temp[i][t].replace("
", ""); result.push(q.replace("
", "")); } } } return result; } //与元数据块中的@grant值相对应,功能是生成一个style样式 GM_addStyle('#down_video_btn{color:#fa7d3c;}'); //下载按钮的html代码 var down_btn_html = ''; down_btn_html += '下载访客详情关键词'; down_btn_html += ''; var inner = document.createElement('span'); inner.innerHTML = down_btn_html; //将以上拼接的html代码插入到网页标签中 var ul_tag = document.getElementsByClassName('batch-btn')[0].parentNode; console.log(ul_tag); if (ul_tag) { ul_tag.append(inner); } var btn = document.getElementById('down_video_btn'); btn.onclick = function(){ var nextBtn = document.getElementsByClassName('ui-pagination-next')[0]; if(!(nextBtn.classList.contains('ui-pagination-disabled'))){ globalAllresult.push(collectKeywords()); nextBtn.click(); }else{ globalAllresult.push(collectKeywords()); // 全收集完后可选数组降维和去重 globalAllresult = [].concat(...globalAllresult); //globalAllresult = Array.from(new Set([].concat(...globalAllresult))); for (var i = 0; i < globalAllresult.length; i++) { globalAllresult[i] = '\n'+globalAllresult[i]; } globalAllresult = String(globalAllresult); console.save(globalAllresult,"collectedKeyWords.csv") } // 下载数据,第一个参数是数据对象,第二个参数是要保存成文件的名字。 }