{
"name": "淘宝批量导出",
"description" : "淘宝批量导出插件",
"version": "1.1",
"manifest_version": 2,
"icons": {
"48": "img/logo02.png"
},
"background": {
"scripts": [
"js/jquery-1.8.3.min.js"
]
},
"permissions": [
"webRequestBlocking",
"tabs",
"webRequest",
"http://*/",
"https://*/",
"alarms"
],
"content_scripts": [
{
"//": "淘宝搜索页面",
"matches": [
"https://s.taobao.com/search*",
"http://s.taobao.com/search*"
],
"css": [
"css/index.css",
"css/layui.css"
],
"js": [
"js/jquery-1.8.3.min.js",
"js/taobao.js"
],
"run_at": "document_idle"
},
{
"//": "淘宝店铺搜索页面",
"matches": [
"https://shopsearch.taobao.com/search*",
"http://shopsearch.taobao.com/search*"
],
"css": [
"css/index.css",
"css/layui.css"
],
"js": [
"js/jquery-1.8.3.min.js",
"js/taobaoshop.js"
],
"run_at": "document_idle"
}
],
"commands": {
"_execute_browser_action": {
"suggested_key": {
"default": "Ctrl+Shift+F",
"mac": "MacCtrl+Shift+F"
},
"description": "Opens hello.html"
}
},
"content_security_policy": "script-src 'self' 'unsafe-eval'; object-src 'self'"
}
淘宝插件目录结构
淘宝导出核心代码js 写入taobao.js
setTimeout(function () {
$("#mainsrp-header > div > div > div > div.logo").append('<div class="burst-button" style="width: 800px;"></div>')
$(".burst-button").append(`<button id='button' class='download layui-btn layui-btn-normal'>导出全部表格</button>`)
$(".burst-button").append(`<div class="layui-input-block"> <input id="pageTest" type="text" name="title" placeholder="请输入页码!" autocomplete="off" class="layui-input"> </div><button id="onclickpageall" class='all layui-btn layui-btn-normal'>导出指定的页数</button>`)
$(".burst-button").append("<button id='addonclickpageall' class='all layui-btn layui-btn-normal'>添加当前页为导出页</button>")
$(".burst-button").append("<button id='addonclickpagealltianjia' class='allnot layui-btn layui-btn-normal' style='background-color: red;'>导出添加的页</button>")
//getAll();
//allPage();
var btn = document.getElementById("button");
btn.onclick =function(){
allPage()
}
var onclickpageall = document.getElementById("onclickpageall");
onclickpageall.onclick =function(){
appointpage()
}
var addonclickpageall = document.getElementById("addonclickpageall");
addonclickpageall.onclick =function(){
addonclickpage()
}
var addonclickpagealltianjia = document.getElementById("addonclickpagealltianjia");
addonclickpagealltianjia.onclick =function(){
addonclickpagetianjia()
}
}, 2000)
// 导出local storage
function addonclickpagetianjia(){
var getlisttaobaodata = JSON.parse(localStorage.getItem('taobaodata'))
excelToTableTaobao(getlisttaobaodata)
// 清除localStorage
localStorage.removeItem("taobaodata")
}
// 添加导出页
function addonclickpage(){
var k = getQueryVariable('s') / 44
var q = $("#q").val()
var datalist = getAll(q,k).data
// localStorage.setItem("taobaodata",JSON.stringify(datalist));
addonclickpagetianjiahebing(datalist)
}
// 追加合并页
function addonclickpagetianjiahebing(datalist){
try{
var getlisttaobaodata = JSON.parse(localStorage.getItem('taobaodata'))
if(getlisttaobaodata == "" || getlisttaobaodata == null || getlisttaobaodata == undefined){
getlisttaobaodata = []
}
}catch(erre){
var getlisttaobaodata = []
}
list = []
Array.prototype.push.apply(list, datalist);
Array.prototype.push.apply(list, getlisttaobaodata);
localStorage.setItem("taobaodata",JSON.stringify(list));
}
// 导出指定页数
function appointpage(){
var appointpage = $('#pageTest').val()
if(!isNaN(appointpage)){
var q = $("#q").val()
list = []
try{
for (k = 1; k <= appointpage ; k++) {
try{
console.log(k)
datalist = getAll(q,k)
Array.prototype.push.apply(list,datalist.data);
}catch(erre){
}
}
}catch(erre){
}
excelToTableTaobao(list)
}else{
alert("请输入数字!")
}
}
// 获取全部页数和页码
function allPage(){
var q = $("#q").val()
var total = $(".total").text().trim().toString().replace(/[^0-9]/ig,"");
list = []
for (s = 1; s < total; s++) {
try{
datalist = getAll(q,s)
Array.prototype.push.apply(list,datalist.data);
}catch(erre){
break
}
}
excelToTableTaobao(list)
}
//获取全部数据
function getAll(q,page){
maplist = {}
$.ajax({
type: "GET",
async:false,
url: 'https://s.taobao.com/search',
data:{
"data-key":"s",
"data-value":page*44,
"ajax":"true",
"q":q,
"ie":"utf8",
"cps":"yes",
"bcoffset":"3",
"ntoffset":"0",
"p4ppushleft":"1,48",
"s":(page-1)*44,
},
success : function(json){
try{
var page = json.mods.pager.data.totalPage
maplist={
"data":jiexitaobao(json.mods.itemlist.data.auctions),
"page":page
}
}catch(erre){
maplist={
"data":[],
"page":101
}
}
},
error:function(json){
}
})
return maplist;
}
// 解析数据
function jiexitaobao(data){
const list = []
for (m = 0; m < data.length; m++) {
sleepDate(1000)
try{
//var itemsdate = items(data[i].nid);
list.push(items(data[m].nid));
}catch(err){
console.log("报错")
}
}
return list
}
// 获取单个数据的详情
function items(nid){
var datas;
$.ajax({
type: "GET",
async:false,
url: 'https://h5api.m.taobao.com/h5/mtop.taobao.detail.getdetail/6.0?v=6.0&data=itemNumId%22%3A%22'+nid+'%22%7D&qq-pf-to=pcqq.c2c',
success : function(json){
console.log(json)
var itemsDataJson = json.data.apiStack[0].value.replace(/\n/g,"\\n").replace(/\r/g,"\\r")
try{
itemsDataJson = JSON.parse(itemsDataJson);
}catch(exception){
console.log(exception)
}
var sku = jiagejiexi(itemsDataJson)//商品套餐
var consumerProtection = shoptiaojian(itemsDataJson)//卖家承诺
var title = json.data.item.title//商品标题
var itemId = json.data.item.itemId//商品id
try{
var priceText = itemsDataJson.priceSectionData.price.priceText //价格区间
}catch(exception){
var priceText = ""
}
var from = itemsDataJson.delivery.from //发货地
var categoryId = json.data.item.categoryId//产品类目
var favcount = json.data.item.favcount//收藏个数
var commentCount = json.data.item.commentCount//评论个数
var userId = json.data.seller.userId//店铺用户id
var shopId = json.data.seller.shopId//店铺id
var shopName = json.data.seller.shopName//店铺名字
var certText = json.data.seller.certText//卖家荣誉
var allItemCount = json.data.seller.allItemCount//店铺商品个数
var shopCard = json.data.seller.shopCard//热卖商品
var shopType = json.data.seller.shopType//店铺等级
var sellerNick = json.data.seller.sellerNick//旺旺名字
try{
var propsCut = json.data.seller.propsCut//产品特点
}catch(exception){
var propsCut = ""
}
try{
var content = itemsDataJson.priceSectionData.promotion.items[0].content//券
}catch(exception){
var content = ""
}
var groupProps = JSON.stringify(json.data.props.groupProps).toString()//属性
groupProps = groupProps.replace(/]/g,"")
groupProps = groupProps.replace(/\[/g,"")
groupProps = groupProps.replace(/{/g,"")
groupProps = groupProps.replace(/}/g,"")
groupProps = groupProps.replace(/,/g,"")
var starts = json.data.seller.starts//开店时间
var shopCard = json.data.seller.shopCard//最近上新
var postage = itemsDataJson.delivery.postage //运费
var vagueSellCount = itemsDataJson.item.vagueSellCount
var datamap = {
"title":title,
"url":"https://detail.tmall.com/item.htm?id="+itemId,
"itemId":itemId,
"priceText":priceText,
"from":from,
"categoryId":categoryId,
"favcount":favcount,
"commentCount":commentCount,
"userId":userId,
"shopId":shopId,
"shopName":shopName,
"certText":certText,
"allItemCount":allItemCount,
"shopCard":shopCard,
"shopType":shopType,
"sellerNick":sellerNick,
"propsCut":propsCut,
"content":content,
"groupProps":groupProps,
"sku":sku,
"starts":starts,
"postage":postage,
"consumerProtection":consumerProtection,
"vagueSellCount":vagueSellCount
}
datas = datamap
},
error:function(json){
console.log(json)
}
})
return datas
}
function excelToTableTaobao(jsonData){
console.log(jsonData)
//列标题,逗号隔开,每一个逗号就是隔开一个单元格
let str = `商品标题,链接,商品id,价格区间,发货地,产品类目,收藏个数,评论个数,店铺用户id,店铺id,店铺名字,卖家荣誉,店铺商品个数,热卖商品,店铺等级,旺旺名字,产品特点,券,属性,套餐,开店时间,运费,卖家承诺,销量\n`;
//增加\t为了不让表格显示科学计数法或者其他格式
for(let i = 0 ; i < jsonData.length ; i++ ){
for(let item in jsonData[i]){
str+=`${jsonData[i][item] + '\t'},`;
}
str+='\n';
}
//encodeURIComponent解决中文乱码
// let uri = 'data:text/csv;charset=utf-8,\ufeff' + encodeURIComponent(str);
var blob = new Blob([str], {
type: "text/plain;charset=utf-8"
});
//解决中文乱码问题
blob = new Blob([String.fromCharCode(0xFEFF), blob], {
type: blob.type
});
object_url = window.URL.createObjectURL(blob);
//通过创建a标签实现
let link = document.createElement("a");
link.href = object_url;
//对下载的文件命名
var q = $("#q").val()
link.download = "淘宝:"+q+"数据下载.csv";
document.body.appendChild(link);
link.click();
document.body.removeChild(link);
}
//价格解析
function jiagejiexi(data){
var neiringStr = ''
try{
var skus = data.skuBase.skus
for(let i = 0 ; i < skus.length ; i++ ){
var skuId = skus[i]['skuId'].toString()
var propPath = skus[i]['propPath'].toString().split(":")
itemsdatajiage = neijiagejiexi(data,skuId,propPath[0],propPath[1])
neiringStr = neiringStr + itemsdatajiage + ' '
}
return neiringStr
}catch(exception){
return neiringStr
}
}
// 店铺条件
function shoptiaojian(data){
try{
var dataitems = data.consumerProtection.items
var titleStr = ' '
for(let j = 0 ; j < dataitems.length ; j++ ){
var title = dataitems[j].title
titleStr = titleStr + title +' '
}
return titleStr
}catch(exception){
return ''
}
}
// 价格里面的解析
function neijiagejiexi(data,skuId,one,tow){
var skuitems = data.skuCore.sku2info[skuId]//价格详情
var skuBaseProps = data.skuBase.props
for(let j = 0 ; j < skuBaseProps.length ; j++ ){
if(skuBaseProps[j].pid==one){
var skuBasePropsvalues = skuBaseProps[j].values
for(let k = 0 ; k < skuBasePropsvalues.length ; k++ ){
if(skuBasePropsvalues[k].vid==tow){
var name = skuBasePropsvalues[k].name
var priceText = skuitems.price.priceText
try{
var subPricepriceTitle = skuitems.subPrice.priceTitle
}catch(exception){
var subPricepriceTitle = ''
}
try{
var subPricepriceText = skuitems.subPrice.priceText
}catch(exception){
var subPricepriceText = ''
}
var itemsdatajiage = '套餐:' + name+' '+'原价:'+priceText+' '+subPricepriceTitle+':'+subPricepriceText
return itemsdatajiage
}
}
}
}
}
// 暂定指定时间
function sleepDate(d){
for(var t = Date.now();Date.now() - t <= d;);
}
// 获取url参数
function getQueryVariable(variable){
var query = window.location.search.substring(1);
var vars = query.split("&");
for (var i=0;i<vars.length;i++) {
var pair = vars[i].split("=");
if(pair[0] == variable){return pair[1];}
}
return(false);
}
index.css
.layui-input{
width: 20rem;
}
.layui-form-item{
margin-left: 1%;
}
.layui-form{
margin-top: 10%;
margin-bottom: 10%;
}
.ziji{
width: 600px;
}
.ziji-h2{
margin: auto;
display: block;
width: 50%;
text-align: center;
color: #1E9FFF;
}
.layui-btn-normal{
margin: auto;
display: block;
}
.response-wider .m-itemlist .grid .item{
color:blue;
height:430px!important;
}
.items-auto{
margin: 10px auto !important;;
width: 80%;;
}
.layui-btn-xs{
margin-bottom: 10px;
}
.gouxuan{
right: auto;
left: 0;
width: 16px;
height: 16px;
line-height: 16px;
border: 1px solid #d2d2d2;
font-size: 12px;
border-radius: 2px;
background-color: #fff;
margin: 10px;
}
.goods-list-v2 .gl-item{
height:500px !important;
}
.layui-btn-normal {
margin-top: 1.3%;
margin-left: 5%;
}
.m-itemlist .grid .item-ctx-hover .icon-has-more,.m-itemlist .grid .item-ctx-hover .row-4{
overflow:hidden !important;
}
/* .m-itemlist .grid .item{
height: 400px !important;
} */
.layui-input-block{
display: -webkit-inline-box;
margin: 0 !important;
padding: 0 !important;
}
.layui-input{
margin: 0 !important;
padding: 0 !important;
}
.layui-input-block{
margin-top: 1.3% !important;
margin-left: 5% !important;
}
jquery-1.8.3.min.js、layui.css不用修改直接用官方的就好
然后去UC浏览器安装
点击设置
找到插件文件夹,点击确定就好
点击导出就可以导出了