Skip to content

Instantly share code, notes, and snippets.

@qiansen1386
Last active December 19, 2016 05:00
Show Gist options
  • Save qiansen1386/d2bdf13b7497aeb8fc68a100d213226c to your computer and use it in GitHub Desktop.
Save qiansen1386/d2bdf13b7497aeb8fc68a100d213226c to your computer and use it in GitHub Desktop.
提取淘宝的所有快递单号到电子表格
{
// Get Item Names
const itemElms = document.querySelectorAll('[class^="index-mod__order-container___"]');
console.log(itemElms);
//let firstElm = fp.first(itemElms);
const findName = itemElm => itemElm.querySelector('span[style="line-height:16px;"]').textContent;
const findNumber = itemElm => itemElm.querySelector('label[class^="bought-wrapper-mod__checkbox-label___"] + span>span:nth-child(3)').textContent;
const concatTarget = itemElm => ({ 'name': findName(itemElm), 'bizOrderId': findNumber(itemElm) });
const fetchExpressStatus = object => {
fetch(`https://buyertrade.taobao.com/trade/json/transit_step.do?bizOrderId=${object.bizOrderId}`, { credentials: 'same-origin' }).then(res => res.json()).then(json => object['express'] = json);
return object;
};
const flatternExpress = object => {
if (object.express) {
object['expressName'] = object.express.expressName;
object['isSuccess'] = object.express.isSuccess;
object['expressId'] = object.express.expressId;
}
return object;
};
let fetchAllBroughtItem = _.flow(
concatTarget,
fetchExpressStatus,
flatternExpress
);
var finalObjects = _.map(fetchAllBroughtItem)(itemElms);
let items = finalObjects;
console.log(items);
console.log(_.reduce(items, (s,o) => s + `${o.expressName}\t${o.expressId}\t${o.name}\t${o.isSuccess}\n`, ""));
}

使用说明

  1. 跳到购买列表
  2. 鼠标 hover 一遍所有的物流记录,保证每个 Tooltips 都弹出来一遍。
  3. 用我的lodash-fp injection.js脚本注入 Lodash/fp
  4. 在 Console 里调用我的代码(复制粘贴),然后把 console 的 output 复制到 Google Spreadsheets 里面

样例输出

| 商品名 | 韵达快递 | 1000010086100101230612315 |

须知

请勿使用! 已知问题:1. Chrome fetch gbk 格式的 json,有乱码。垃圾 Chrome 毁我青春~

@qiansen1386
Copy link
Author

qiansen1386 commented Dec 15, 2016

TODO:

  • 完成原型实验
  • 改成 const 定型测试
  • 完全函数化(mdzz)
  • 减肥 -> 改成函数嵌套,并 uglify 压缩最好3行以内搞定。(完全无视代码复用和可读性)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment