1. {
    2. "name": "淘宝批量导出",
    3. "description" : "淘宝批量导出插件",
    4. "version": "1.1",
    5. "manifest_version": 2,
    6. "icons": {
    7. "48": "img/logo02.png"
    8. },
    9. "background": {
    10. "scripts": [
    11. "js/jquery-1.8.3.min.js"
    12. ]
    13. },
    14. "permissions": [
    15. "webRequestBlocking",
    16. "tabs",
    17. "webRequest",
    18. "http://*/",
    19. "https://*/",
    20. "alarms"
    21. ],
    22. "content_scripts": [
    23. {
    24. "//": "淘宝搜索页面",
    25. "matches": [
    26. "https://s.taobao.com/search*",
    27. "http://s.taobao.com/search*"
    28. ],
    29. "css": [
    30. "css/index.css",
    31. "css/layui.css"
    32. ],
    33. "js": [
    34. "js/jquery-1.8.3.min.js",
    35. "js/taobao.js"
    36. ],
    37. "run_at": "document_idle"
    38. },
    39. {
    40. "//": "淘宝店铺搜索页面",
    41. "matches": [
    42. "https://shopsearch.taobao.com/search*",
    43. "http://shopsearch.taobao.com/search*"
    44. ],
    45. "css": [
    46. "css/index.css",
    47. "css/layui.css"
    48. ],
    49. "js": [
    50. "js/jquery-1.8.3.min.js",
    51. "js/taobaoshop.js"
    52. ],
    53. "run_at": "document_idle"
    54. }
    55. ],
    56. "commands": {
    57. "_execute_browser_action": {
    58. "suggested_key": {
    59. "default": "Ctrl+Shift+F",
    60. "mac": "MacCtrl+Shift+F"
    61. },
    62. "description": "Opens hello.html"
    63. }
    64. },
    65. "content_security_policy": "script-src 'self' 'unsafe-eval'; object-src 'self'"
    66. }

    淘宝插件目录结构
    image.png
    淘宝导出核心代码js 写入taobao.js

    1. setTimeout(function () {
    2. $("#mainsrp-header > div > div > div > div.logo").append('<div class="burst-button" style="width: 800px;"></div>')
    3. $(".burst-button").append(`<button id='button' class='download layui-btn layui-btn-normal'>导出全部表格</button>`)
    4. $(".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>`)
    5. $(".burst-button").append("<button id='addonclickpageall' class='all layui-btn layui-btn-normal'>添加当前页为导出页</button>")
    6. $(".burst-button").append("<button id='addonclickpagealltianjia' class='allnot layui-btn layui-btn-normal' style='background-color: red;'>导出添加的页</button>")
    7. //getAll();
    8. //allPage();
    9. var btn = document.getElementById("button");
    10. btn.onclick =function(){
    11. allPage()
    12. }
    13. var onclickpageall = document.getElementById("onclickpageall");
    14. onclickpageall.onclick =function(){
    15. appointpage()
    16. }
    17. var addonclickpageall = document.getElementById("addonclickpageall");
    18. addonclickpageall.onclick =function(){
    19. addonclickpage()
    20. }
    21. var addonclickpagealltianjia = document.getElementById("addonclickpagealltianjia");
    22. addonclickpagealltianjia.onclick =function(){
    23. addonclickpagetianjia()
    24. }
    25. }, 2000)
    26. // 导出local storage
    27. function addonclickpagetianjia(){
    28. var getlisttaobaodata = JSON.parse(localStorage.getItem('taobaodata'))
    29. excelToTableTaobao(getlisttaobaodata)
    30. // 清除localStorage
    31. localStorage.removeItem("taobaodata")
    32. }
    33. // 添加导出页
    34. function addonclickpage(){
    35. var k = getQueryVariable('s') / 44
    36. var q = $("#q").val()
    37. var datalist = getAll(q,k).data
    38. // localStorage.setItem("taobaodata",JSON.stringify(datalist));
    39. addonclickpagetianjiahebing(datalist)
    40. }
    41. // 追加合并页
    42. function addonclickpagetianjiahebing(datalist){
    43. try{
    44. var getlisttaobaodata = JSON.parse(localStorage.getItem('taobaodata'))
    45. if(getlisttaobaodata == "" || getlisttaobaodata == null || getlisttaobaodata == undefined){
    46. getlisttaobaodata = []
    47. }
    48. }catch(erre){
    49. var getlisttaobaodata = []
    50. }
    51. list = []
    52. Array.prototype.push.apply(list, datalist);
    53. Array.prototype.push.apply(list, getlisttaobaodata);
    54. localStorage.setItem("taobaodata",JSON.stringify(list));
    55. }
    56. // 导出指定页数
    57. function appointpage(){
    58. var appointpage = $('#pageTest').val()
    59. if(!isNaN(appointpage)){    
    60. var q = $("#q").val()
    61. list = []
    62. try{
    63. for (k = 1; k <= appointpage ; k++) {
    64. try{
    65. console.log(k)
    66. datalist = getAll(q,k)
    67. Array.prototype.push.apply(list,datalist.data);
    68. }catch(erre){
    69. }
    70. }
    71. }catch(erre){
    72. }
    73. excelToTableTaobao(list)
    74.   }else{
    75. alert("请输入数字!")
    76. }
    77. }
    78. // 获取全部页数和页码
    79. function allPage(){
    80. var q = $("#q").val()
    81. var total = $(".total").text().trim().toString().replace(/[^0-9]/ig,"");
    82. list = []
    83. for (s = 1; s < total; s++) {
    84. try{
    85. datalist = getAll(q,s)
    86. Array.prototype.push.apply(list,datalist.data);
    87. }catch(erre){
    88. break
    89. }
    90. }
    91. excelToTableTaobao(list)
    92. }
    93. //获取全部数据
    94. function getAll(q,page){
    95. maplist = {}
    96. $.ajax({
    97. type: "GET",
    98. async:false,
    99. url: 'https://s.taobao.com/search',
    100. data:{
    101. "data-key":"s",
    102. "data-value":page*44,
    103. "ajax":"true",
    104. "q":q,
    105. "ie":"utf8",
    106. "cps":"yes",
    107. "bcoffset":"3",
    108. "ntoffset":"0",
    109. "p4ppushleft":"1,48",
    110. "s":(page-1)*44,
    111. },
    112. success : function(json){
    113. try{
    114. var page = json.mods.pager.data.totalPage
    115. maplist={
    116. "data":jiexitaobao(json.mods.itemlist.data.auctions),
    117. "page":page
    118. }
    119. }catch(erre){
    120. maplist={
    121. "data":[],
    122. "page":101
    123. }
    124. }
    125. },
    126. error:function(json){
    127. }
    128. })
    129. return maplist;
    130. }
    131. // 解析数据
    132. function jiexitaobao(data){
    133. const list = []
    134. for (m = 0; m < data.length; m++) {
    135. sleepDate(1000)
    136. try{
    137. //var itemsdate = items(data[i].nid);
    138. list.push(items(data[m].nid));
    139. }catch(err){
    140. console.log("报错")
    141. }
    142. }
    143. return list
    144. }
    145. // 获取单个数据的详情
    146. function items(nid){
    147. var datas;
    148. $.ajax({
    149. type: "GET",
    150. async:false,
    151. 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',
    152. success : function(json){
    153. console.log(json)
    154. var itemsDataJson = json.data.apiStack[0].value.replace(/\n/g,"\\n").replace(/\r/g,"\\r")
    155. try{
    156. itemsDataJson = JSON.parse(itemsDataJson);
    157. }catch(exception){
    158. console.log(exception)
    159. }
    160. var sku = jiagejiexi(itemsDataJson)//商品套餐
    161. var consumerProtection = shoptiaojian(itemsDataJson)//卖家承诺
    162. var title = json.data.item.title//商品标题
    163. var itemId = json.data.item.itemId//商品id
    164. try{
    165. var priceText = itemsDataJson.priceSectionData.price.priceText //价格区间
    166. }catch(exception){
    167. var priceText = ""
    168. }
    169. var from = itemsDataJson.delivery.from //发货地
    170. var categoryId = json.data.item.categoryId//产品类目
    171. var favcount = json.data.item.favcount//收藏个数
    172. var commentCount = json.data.item.commentCount//评论个数
    173. var userId = json.data.seller.userId//店铺用户id
    174. var shopId = json.data.seller.shopId//店铺id
    175. var shopName = json.data.seller.shopName//店铺名字
    176. var certText = json.data.seller.certText//卖家荣誉
    177. var allItemCount = json.data.seller.allItemCount//店铺商品个数
    178. var shopCard = json.data.seller.shopCard//热卖商品
    179. var shopType = json.data.seller.shopType//店铺等级
    180. var sellerNick = json.data.seller.sellerNick//旺旺名字
    181. try{
    182. var propsCut = json.data.seller.propsCut//产品特点
    183. }catch(exception){
    184. var propsCut = ""
    185. }
    186. try{
    187. var content = itemsDataJson.priceSectionData.promotion.items[0].content//券
    188. }catch(exception){
    189. var content = ""
    190. }
    191. var groupProps = JSON.stringify(json.data.props.groupProps).toString()//属性
    192. groupProps = groupProps.replace(/]/g,"")
    193. groupProps = groupProps.replace(/\[/g,"")
    194. groupProps = groupProps.replace(/{/g,"")
    195. groupProps = groupProps.replace(/}/g,"")
    196. groupProps = groupProps.replace(/,/g,"")
    197. var starts = json.data.seller.starts//开店时间
    198. var shopCard = json.data.seller.shopCard//最近上新
    199. var postage = itemsDataJson.delivery.postage //运费
    200. var vagueSellCount = itemsDataJson.item.vagueSellCount
    201. var datamap = {
    202. "title":title,
    203. "url":"https://detail.tmall.com/item.htm?id="+itemId,
    204. "itemId":itemId,
    205. "priceText":priceText,
    206. "from":from,
    207. "categoryId":categoryId,
    208. "favcount":favcount,
    209. "commentCount":commentCount,
    210. "userId":userId,
    211. "shopId":shopId,
    212. "shopName":shopName,
    213. "certText":certText,
    214. "allItemCount":allItemCount,
    215. "shopCard":shopCard,
    216. "shopType":shopType,
    217. "sellerNick":sellerNick,
    218. "propsCut":propsCut,
    219. "content":content,
    220. "groupProps":groupProps,
    221. "sku":sku,
    222. "starts":starts,
    223. "postage":postage,
    224. "consumerProtection":consumerProtection,
    225. "vagueSellCount":vagueSellCount
    226. }
    227. datas = datamap
    228. },
    229. error:function(json){
    230. console.log(json)
    231. }
    232. })
    233. return datas
    234. }
    235. function excelToTableTaobao(jsonData){
    236. console.log(jsonData)
    237. //列标题,逗号隔开,每一个逗号就是隔开一个单元格
    238. let str = `商品标题,链接,商品id,价格区间,发货地,产品类目,收藏个数,评论个数,店铺用户id,店铺id,店铺名字,卖家荣誉,店铺商品个数,热卖商品,店铺等级,旺旺名字,产品特点,券,属性,套餐,开店时间,运费,卖家承诺,销量\n`;
    239. //增加\t为了不让表格显示科学计数法或者其他格式
    240. for(let i = 0 ; i < jsonData.length ; i++ ){
    241. for(let item in jsonData[i]){
    242. str+=`${jsonData[i][item] + '\t'},`;
    243. }
    244. str+='\n';
    245. }
    246. //encodeURIComponent解决中文乱码
    247. // let uri = 'data:text/csv;charset=utf-8,\ufeff' + encodeURIComponent(str);
    248. var blob = new Blob([str], {
    249. type: "text/plain;charset=utf-8"
    250. });
    251. //解决中文乱码问题
    252. blob = new Blob([String.fromCharCode(0xFEFF), blob], {
    253. type: blob.type
    254. });
    255. object_url = window.URL.createObjectURL(blob);
    256. //通过创建a标签实现
    257. let link = document.createElement("a");
    258. link.href = object_url;
    259. //对下载的文件命名
    260. var q = $("#q").val()
    261. link.download = "淘宝:"+q+"数据下载.csv";
    262. document.body.appendChild(link);
    263. link.click();
    264. document.body.removeChild(link);
    265. }
    266. //价格解析
    267. function jiagejiexi(data){
    268. var neiringStr = ''
    269. try{
    270. var skus = data.skuBase.skus
    271. for(let i = 0 ; i < skus.length ; i++ ){
    272. var skuId = skus[i]['skuId'].toString()
    273. var propPath = skus[i]['propPath'].toString().split(":")
    274. itemsdatajiage = neijiagejiexi(data,skuId,propPath[0],propPath[1])
    275. neiringStr = neiringStr + itemsdatajiage + ' '
    276. }
    277. return neiringStr
    278. }catch(exception){
    279. return neiringStr
    280. }
    281. }
    282. // 店铺条件
    283. function shoptiaojian(data){
    284. try{
    285. var dataitems = data.consumerProtection.items
    286. var titleStr = ' '
    287. for(let j = 0 ; j < dataitems.length ; j++ ){
    288. var title = dataitems[j].title
    289. titleStr = titleStr + title +' '
    290. }
    291. return titleStr
    292. }catch(exception){
    293. return ''
    294. }
    295. }
    296. // 价格里面的解析
    297. function neijiagejiexi(data,skuId,one,tow){
    298. var skuitems = data.skuCore.sku2info[skuId]//价格详情
    299. var skuBaseProps = data.skuBase.props
    300. for(let j = 0 ; j < skuBaseProps.length ; j++ ){
    301. if(skuBaseProps[j].pid==one){
    302. var skuBasePropsvalues = skuBaseProps[j].values
    303. for(let k = 0 ; k < skuBasePropsvalues.length ; k++ ){
    304. if(skuBasePropsvalues[k].vid==tow){
    305. var name = skuBasePropsvalues[k].name
    306. var priceText = skuitems.price.priceText
    307. try{
    308. var subPricepriceTitle = skuitems.subPrice.priceTitle
    309. }catch(exception){
    310. var subPricepriceTitle = ''
    311. }
    312. try{
    313. var subPricepriceText = skuitems.subPrice.priceText
    314. }catch(exception){
    315. var subPricepriceText = ''
    316. }
    317. var itemsdatajiage = '套餐:' + name+' '+'原价:'+priceText+' '+subPricepriceTitle+':'+subPricepriceText
    318. return itemsdatajiage
    319. }
    320. }
    321. }
    322. }
    323. }
    324. // 暂定指定时间
    325. function sleepDate(d){
    326. for(var t = Date.now();Date.now() - t <= d;);
    327. }
    328. // 获取url参数
    329. function getQueryVariable(variable){
    330. var query = window.location.search.substring(1);
    331. var vars = query.split("&");
    332. for (var i=0;i<vars.length;i++) {
    333. var pair = vars[i].split("=");
    334. if(pair[0] == variable){return pair[1];}
    335. }
    336. return(false);
    337. }

    index.css

    1. .layui-input{
    2. width: 20rem;
    3. }
    4. .layui-form-item{
    5. margin-left: 1%;
    6. }
    7. .layui-form{
    8. margin-top: 10%;
    9. margin-bottom: 10%;
    10. }
    11. .ziji{
    12. width: 600px;
    13. }
    14. .ziji-h2{
    15. margin: auto;
    16. display: block;
    17. width: 50%;
    18. text-align: center;
    19. color: #1E9FFF;
    20. }
    21. .layui-btn-normal{
    22. margin: auto;
    23. display: block;
    24. }
    25. .response-wider .m-itemlist .grid .item{
    26. color:blue;
    27. height:430px!important;
    28. }
    29. .items-auto{
    30. margin: 10px auto !important;;
    31. width: 80%;;
    32. }
    33. .layui-btn-xs{
    34. margin-bottom: 10px;
    35. }
    36. .gouxuan{
    37. right: auto;
    38. left: 0;
    39. width: 16px;
    40. height: 16px;
    41. line-height: 16px;
    42. border: 1px solid #d2d2d2;
    43. font-size: 12px;
    44. border-radius: 2px;
    45. background-color: #fff;
    46. margin: 10px;
    47. }
    48. .goods-list-v2 .gl-item{
    49. height:500px !important;
    50. }
    51. .layui-btn-normal {
    52. margin-top: 1.3%;
    53. margin-left: 5%;
    54. }
    55. .m-itemlist .grid .item-ctx-hover .icon-has-more,.m-itemlist .grid .item-ctx-hover .row-4{
    56. overflow:hidden !important;
    57. }
    58. /* .m-itemlist .grid .item{
    59. height: 400px !important;
    60. } */
    61. .layui-input-block{
    62. display: -webkit-inline-box;
    63. margin: 0 !important;
    64. padding: 0 !important;
    65. }
    66. .layui-input{
    67. margin: 0 !important;
    68. padding: 0 !important;
    69. }
    70. .layui-input-block{
    71. margin-top: 1.3% !important;
    72. margin-left: 5% !important;
    73. }

    jquery-1.8.3.min.js、layui.css不用修改直接用官方的就好
    然后去UC浏览器安装

    点击设置

    image.png
    image.png

    找到插件文件夹,点击确定就好

    image.png

    点击导出就可以导出了