Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save staticfire/70f1ec375fc0b2063e831c27a88155c7 to your computer and use it in GitHub Desktop.

Select an option

Save staticfire/70f1ec375fc0b2063e831c27a88155c7 to your computer and use it in GitHub Desktop.
导出淘宝购物车物品清单和价格
/* 使用方法:
1. 打开你的淘宝购物车页面。
2. 按 F12,进入 Console。
3. 粘贴代码,回车。
*/
function autoScrollToBottom(callback) {
let lastScrollTop = -1;
let timer = setInterval(() => {
window.scrollBy(0, 1000); // 每次向下滚动 1000 像素
let currentScrollTop = document.documentElement.scrollTop || document.body.scrollTop;
// 如果已经到底(滚不动了)
if (currentScrollTop === lastScrollTop) {
clearInterval(timer);
console.log('✅ 已滚动到底部,商品应该都加载完成啦!');
if (typeof callback === 'function') callback();
} else {
lastScrollTop = currentScrollTop;
}
}, 500); // 每 500ms 滚一次
}
autoScrollToBottom(() => {
// 👇这里粘贴之前提取标题 + 价格的代码
const items = Array.from(document.querySelectorAll('.cartItemDPQContainer--S7yQtAoY')).map(item => {
const title = item.querySelector('a.title--dsuLK9IN')?.title?.trim() || '无标题';
const priceInteger = item.querySelector('.trade-price-integer')?.innerText?.trim() || '??';
const priceDecimal = item.querySelector('.trade-price-fraction')?.innerText?.trim() || '00';
return `${title} - ¥${priceInteger}.${priceDecimal}`;
});
console.log(items.join('\n'));
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment