目前尚未对自动停止做完善
// ==UserScript==
// @name 淘宝自动翻页下载助手
// @namespace http://tampermonkey.net/
// @version 0.1
// @description 自动翻页和下载淘宝商品信息,避免被反爬
// @author OrangeThink
// @match https://*.taobao.com/*
// @grant GM_addStyle
// @grant GM_download
// ==/UserScript==
(function() {
'use strict';
// 日志函数(替代console.log)
function log(message) {
console.log(`[淘宝助手] ${message}`);
}
// 随机延时函数(防反爬)
function randomDelay(min, max) {
return Math.floor(Math.random() * (max - min + 1) + min);
}
// 创建控制面板
function createControlPanel() {
const panel = document.createElement('div');
panel.id = 'taobao-helper-panel';
panel.style.cssText = `
position: fixed;
bottom: 20px;
right: 20px;
background: white;
border: 1px solid #ddd;
padding: 10px;
border-radius: 5px;
box-shadow: 0 2px 10px rgba(0,0,0,0.1);
z-index: 9999;
`;
panel.innerHTML = `
<h3>淘宝助手</h3>
<button id="next-page-btn">下一页</button>
<button id="download-btn">下载当前页</button>
<div id="status" style="margin-top: 10px; color: #666;"></div>
`;
document.body.appendChild(panel);
// 添加按钮事件
document.getElementById('next-page-btn').addEventListener('click', goToNextPage);
document.getElementById('download-btn').addEventListener('click', downloadCurrentPage);
}
// 翻页函数
function goToNextPage() {
log('正在翻页...');
updateStatus('正在翻页...');
setTimeout(() => {
// 第二步:点击确认按钮
const nextButton = document.querySelector('.ant-pagination-next').childNodes[0];
if (!nextButton) {
updateStatus("未找到确认按钮");
console.error("未找到确认按钮,请检查选择器或延时时间");
return;
}
// 执行点击
nextButton.click();
log('已点击下一页');
updateStatus('已翻到下一页');
document.querySelector('#download-btn').click();
}, 2000);
}
// 下载当前页面数据
function downloadCurrentPage() {
log('正在下载当前页面数据...');
updateStatus('正在下载数据...');
// 点击下载按钮(需要根据实际页面结构调整选择器)
document.querySelector('.exportBtn--jnP1Ru6K').childNodes[0].click();
// 等待确认框出现(2秒延时,可根据实际调整)
setTimeout(() => {
// 第二步:点击确认按钮
const confirmBtn = document.querySelector('.ant-btn-primary');
if (!confirmBtn) {
updateStatus("未找到确认按钮");
console.error("未找到确认按钮,请检查选择器或延时时间");
return;
}
// 执行点击
confirmBtn.click();
updateStatus("已点击确认,下载中...");
console.log("下载流程执行完成");
}, 2000);
// 添加随机延时,模拟人类操作
setTimeout(() => {
document.querySelector('#next-page-btn').click();
log('已点击下一页');
}, randomDelay(1000, 3000));
}
// 更新状态显示
function updateStatus(message) {
const statusElement = document.getElementById('status');
if (statusElement) {
statusElement.textContent = message;
}
}
// 初始化
function init() {
log('淘宝助手已启动');
createControlPanel();
}
// 页面加载完成后初始化
window.addEventListener('load', init);
})();
该页面评论已关闭