Compare commits
2
Commits
90b6c445e2
...
e314881dba
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
e314881dba | ||
|
|
8dfd89a2ce |
+75
-11
@@ -1,9 +1,10 @@
|
|||||||
// ==UserScript==
|
// ==UserScript==
|
||||||
// @name Mysteel 钢铁价格提取器 (双擎透视+缓存+登录校验版)
|
// @name Mysteel 钢铁价格提取器
|
||||||
// @namespace http://tampermonkey.net/
|
// @namespace http://tampermonkey.net/
|
||||||
// @version 6.1
|
// @version 6.2
|
||||||
// @description 合并列表页与详情页的抓取逻辑,统一透视表导出,支持多维筛选及本地缓存,加入登录状态拦截
|
// @description 合并列表页与详情页的抓取逻辑,统一透视表导出csv,支持多维筛选及本地缓存,加入登录状态拦截
|
||||||
// @author ali
|
// @author ali
|
||||||
|
// @mail solitude@hraulein.com
|
||||||
// @match *://*.mysteel.com/market/*
|
// @match *://*.mysteel.com/market/*
|
||||||
// @match *://*.mysteel.com/m/*
|
// @match *://*.mysteel.com/m/*
|
||||||
// @grant none
|
// @grant none
|
||||||
@@ -207,7 +208,7 @@
|
|||||||
function startSingleProcess() {
|
function startSingleProcess() {
|
||||||
// 🔒 登录状态守卫拦截
|
// 🔒 登录状态守卫拦截
|
||||||
if (!isUserLoggedIn()) {
|
if (!isUserLoggedIn()) {
|
||||||
alert('系统检测到您未登录!\n请先登录 Mysteel 账号后再进行数据提取。');
|
showToast('请先登录 Mysteel 账号后再进行数据提取操作。', 'error');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -220,7 +221,7 @@
|
|||||||
// 提取日期:从 <span class="content-info-text publish-time"> 提取
|
// 提取日期:从 <span class="content-info-text publish-time"> 提取
|
||||||
const dateEl = document.querySelector('.content-info-text.publish-time');
|
const dateEl = document.querySelector('.content-info-text.publish-time');
|
||||||
if (!dateEl) {
|
if (!dateEl) {
|
||||||
alert('未找到页面的发布时间,请确认当前网页结构!');
|
showToast('未找到页面的发布时间,请确认当前网页结构!', 'error');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// 提取 "2026-07-24 17:41" 中的 "2026-07-24"
|
// 提取 "2026-07-24 17:41" 中的 "2026-07-24"
|
||||||
@@ -234,11 +235,15 @@
|
|||||||
if (flatData.length > 0) {
|
if (flatData.length > 0) {
|
||||||
generatePivotCSV(flatData, '单日');
|
generatePivotCSV(flatData, '单日');
|
||||||
} else {
|
} else {
|
||||||
alert('根据当前筛选条件,未提取到有效数据!');
|
showToast('根据当前筛选条件,未提取到有效数据!', 'warning');
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
if (error.message === 'NO_PERMISSION') {
|
||||||
|
showToast('当前账号暂无权限查看价格数据,请确认是否已购买或开通相关权限!', 'warning');
|
||||||
|
} else {
|
||||||
console.error('详情页提取出错:', error);
|
console.error('详情页提取出错:', error);
|
||||||
alert('发生错误,请查看控制台日志。');
|
showToast('发生错误,请查看控制台日志。', 'error');
|
||||||
|
}
|
||||||
} finally {
|
} finally {
|
||||||
btn.innerText = originalText;
|
btn.innerText = originalText;
|
||||||
btn.disabled = false;
|
btn.disabled = false;
|
||||||
@@ -251,7 +256,7 @@
|
|||||||
async function startBatchProcess() {
|
async function startBatchProcess() {
|
||||||
// 🔒 登录状态守卫拦截
|
// 🔒 登录状态守卫拦截
|
||||||
if (!isUserLoggedIn()) {
|
if (!isUserLoggedIn()) {
|
||||||
alert('系统检测到您未登录!\n请先登录 Mysteel 账号后再进行批量提取。');
|
showToast('请先登录 Mysteel 账号后再进行批量提取操作。', 'error');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -264,7 +269,7 @@
|
|||||||
btn.innerText = '正在分析列表...';
|
btn.innerText = '正在分析列表...';
|
||||||
const targetLinks = getTargetLinks();
|
const targetLinks = getTargetLinks();
|
||||||
if (targetLinks.length === 0) {
|
if (targetLinks.length === 0) {
|
||||||
alert('未发现符合条件的链接!');
|
showToast('未发现符合条件的链接!', 'warning');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -285,6 +290,7 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
|
if (err.message === 'NO_PERMISSION') throw err;
|
||||||
console.error(`渲染 ${linkObj.date} 失败:`, err);
|
console.error(`渲染 ${linkObj.date} 失败:`, err);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -294,12 +300,16 @@
|
|||||||
if (flatData.length > 0) {
|
if (flatData.length > 0) {
|
||||||
generatePivotCSV(flatData, '批量');
|
generatePivotCSV(flatData, '批量');
|
||||||
} else {
|
} else {
|
||||||
alert('根据当前筛选条件,未能提取到任何数据!');
|
showToast('根据当前筛选条件,未能提取到任何数据!', 'warning');
|
||||||
}
|
}
|
||||||
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
if (error.message === 'NO_PERMISSION') {
|
||||||
|
showToast('当前账号暂无权限查看价格数据,请确认是否已购买或开通相关权限!', 'warning');
|
||||||
|
} else {
|
||||||
console.error('批量处理出错:', error);
|
console.error('批量处理出错:', error);
|
||||||
alert('发生错误,请查看控制台。');
|
showToast('发生错误,请查看控制台。', 'error');
|
||||||
|
}
|
||||||
} finally {
|
} finally {
|
||||||
btn.innerText = originalText;
|
btn.innerText = originalText;
|
||||||
btn.disabled = false;
|
btn.disabled = false;
|
||||||
@@ -311,6 +321,56 @@
|
|||||||
// 公共组件区
|
// 公共组件区
|
||||||
// ==========================================
|
// ==========================================
|
||||||
|
|
||||||
|
// Toast 提示组件
|
||||||
|
function showToast(message, type = 'info') {
|
||||||
|
const toast = document.createElement('div');
|
||||||
|
toast.innerText = message;
|
||||||
|
|
||||||
|
let bgColor = '#1890ff';
|
||||||
|
if (type === 'error') bgColor = '#ff4d4f';
|
||||||
|
else if (type === 'success') bgColor = '#52c41a';
|
||||||
|
else if (type === 'warning') bgColor = '#faad14';
|
||||||
|
|
||||||
|
Object.assign(toast.style, {
|
||||||
|
position: 'fixed',
|
||||||
|
top: '20px',
|
||||||
|
left: '50%',
|
||||||
|
transform: 'translateX(-50%)',
|
||||||
|
backgroundColor: bgColor,
|
||||||
|
color: '#fff',
|
||||||
|
padding: '12px 24px',
|
||||||
|
borderRadius: '4px',
|
||||||
|
boxShadow: '0 4px 12px rgba(0,0,0,0.15)',
|
||||||
|
zIndex: '999999',
|
||||||
|
fontSize: '14px',
|
||||||
|
whiteSpace: 'pre-wrap',
|
||||||
|
opacity: '0',
|
||||||
|
transition: 'opacity 0.3s, top 0.3s',
|
||||||
|
pointerEvents: 'none',
|
||||||
|
textAlign: 'center',
|
||||||
|
lineHeight: '1.5'
|
||||||
|
});
|
||||||
|
|
||||||
|
document.body.appendChild(toast);
|
||||||
|
|
||||||
|
// 动画显示
|
||||||
|
requestAnimationFrame(() => {
|
||||||
|
toast.style.opacity = '1';
|
||||||
|
toast.style.top = '40px';
|
||||||
|
});
|
||||||
|
|
||||||
|
// 定时移除
|
||||||
|
setTimeout(() => {
|
||||||
|
toast.style.opacity = '0';
|
||||||
|
toast.style.top = '20px';
|
||||||
|
setTimeout(() => {
|
||||||
|
if (toast.parentNode) {
|
||||||
|
toast.parentNode.removeChild(toast);
|
||||||
|
}
|
||||||
|
}, 300);
|
||||||
|
}, 5000);
|
||||||
|
}
|
||||||
|
|
||||||
// 获取列表页的日期链接
|
// 获取列表页的日期链接
|
||||||
function getTargetLinks() {
|
function getTargetLinks() {
|
||||||
const listItems = document.querySelectorAll('#articleList .nlist li');
|
const listItems = document.querySelectorAll('#articleList .nlist li');
|
||||||
@@ -392,6 +452,10 @@
|
|||||||
|
|
||||||
if (!tdBreed || !tdSpec || !tdMaterial || !tdPrice) continue;
|
if (!tdBreed || !tdSpec || !tdMaterial || !tdPrice) continue;
|
||||||
|
|
||||||
|
if (tdPrice.querySelector('.icon-key')) {
|
||||||
|
throw new Error('NO_PERMISSION');
|
||||||
|
}
|
||||||
|
|
||||||
const cleanText = (element) => {
|
const cleanText = (element) => {
|
||||||
let clone = element.cloneNode(true);
|
let clone = element.cloneNode(true);
|
||||||
let childIcons = clone.querySelectorAll('a, img, div');
|
let childIcons = clone.querySelectorAll('a, img, div');
|
||||||
|
|||||||
@@ -1,2 +1,56 @@
|
|||||||
# UserScript
|
# Mysteel 钢铁价格提取器
|
||||||
|
|
||||||
|
Mysteel 钢铁价格提取器 (Tampermonkey UserScript) 是一个专为 Mysteel (我的钢铁网) 开发的自动化数据抓取与处理工具。它能够在列表页和详情页中提取钢材价格信息,并自动生成方便分析的透视表 CSV 格式文件进行直接导出。
|
||||||
|
|
||||||
|
## 🌟 核心特性 (v6.1)
|
||||||
|
|
||||||
|
- **双擎工作模式**:
|
||||||
|
- **列表页批量模式 (引擎 B)**:在市场列表页自动识别并遍历每日价格链接,利用隐藏 `iframe` 静默抓取多日数据,最终生成跨越时间维度的价格透视表。
|
||||||
|
- **详情页单日模式 (引擎 A)**:在具体日期详情页直接提取当日价格数据并生成单日透视表。
|
||||||
|
- **多维高级筛选**:内置可配置的悬浮筛选面板,支持按 **类别 (高线/螺纹钢/盘螺)**、**线径 (Φ6 - Φ40)** 和 **材质 (HPB300 等)** 进行精准过滤,只导出关注的数据。
|
||||||
|
- **本地状态缓存**:筛选配置支持本地存储 (LocalStorage),自动保存您上一次选择的过滤条件,一次配置,后续复用。
|
||||||
|
- **智能登录校验**:操作前自动检测 Mysteel 账号的登录状态。若未登录将智能拦截并提示,避免抓取到无效的隐藏数据。
|
||||||
|
- **轻量无侵入 UI**:在页面右下角悬浮显示操作主按钮与设置齿轮。支持鼠标悬停快速查看当前过滤状态,UI 设计现代、简洁且易用。
|
||||||
|
- **数据自动清洗与透视**:提取数据时自动清洗非文本符号(如图标、换行等),对于同一规格材料的多个价格,智能提取最低价格,最终生成以日期为列头的标准二维 CSV 文件,完美适配 Excel 及其他数据分析工具。
|
||||||
|
|
||||||
|
## 🚀 安装指南
|
||||||
|
|
||||||
|
1. 确保您的浏览器已安装用户脚本管理器扩展,推荐使用 [Tampermonkey (油猴)](https://www.tampermonkey.net/)。
|
||||||
|
2. 在 Tampermonkey 控制面板中,点击“添加新脚本”。
|
||||||
|
3. 将本项目中 `MysteelGetMinPrice.js` 文件的所有代码复制,并粘贴覆盖到新建的脚本编辑器中。
|
||||||
|
4. 保存脚本 (Windows/Linux: `Ctrl + S`, macOS: `Cmd + S`)。
|
||||||
|
5. 确保脚本处于开启状态。
|
||||||
|
|
||||||
|
## 📖 使用说明
|
||||||
|
|
||||||
|
### 场景一:列表页批量导出
|
||||||
|
1. 登录 [Mysteel](https://www.mysteel.com/) 账号。
|
||||||
|
2. 导航至某地市场的钢材价格列表页(网址匹配 `https://*.mysteel.com/market/*`)。
|
||||||
|
3. 页面右下角会出现橙色的 **`🚀 批量提取并透视导出`** 按钮。
|
||||||
|
4. 点击齿轮 `⚙️` 图标展开配置面板,勾选您想要筛选的钢材类别、线径和材质,然后点击“保存并关闭”。
|
||||||
|
5. 点击橙色的批量提取按钮,工具会自动开始遍历当前列表页的所有目标链接并在后台逐一提取。
|
||||||
|
6. 提取完成后,浏览器会自动下载名为 `钢材透视价格表_批量_YYYYMMDD.csv` 的文件。
|
||||||
|
|
||||||
|
### 场景二:详情页单日导出
|
||||||
|
1. 登录 Mysteel 账号。
|
||||||
|
2. 导航至某一天的特定价格详情页(网址匹配 `https://*.mysteel.com/m/*`)。
|
||||||
|
3. 页面右下角会出现蓝色的 **`📊 导出当日数据(透视版)`** 按钮。
|
||||||
|
4. 同样可以通过点击齿轮 `⚙️` 预先配置所需的筛选条件。
|
||||||
|
5. 点击蓝色操作按钮,工具将直接读取当前页面的表格数据并进行透视。
|
||||||
|
6. 提取完成后,浏览器会自动下载名为 `钢材透视价格表_单日_YYYYMMDD.csv` 的文件。
|
||||||
|
|
||||||
|
## ⚙️ 匹配网址及权限
|
||||||
|
|
||||||
|
**生效域名 (Match)**:
|
||||||
|
- `*://*.mysteel.com/market/*` (列表页匹配)
|
||||||
|
- `*://*.mysteel.com/m/*` (详情页匹配)
|
||||||
|
|
||||||
|
**权限声明 (Grant)**:
|
||||||
|
- `none` (无特殊越权权限要求,完全基于当前页面 DOM 及标准 Web API 运行,安全可靠)
|
||||||
|
|
||||||
|
**自动更新 (Auto Update)**:
|
||||||
|
- 请在油猴脚本的设置中添加更新地址: `https://gitea.hraulein.com/ali/UserScript/raw/branch/main/MysteelGetMinPrice.js` 并保存
|
||||||
|
|
||||||
|
## 👨💻 开发者
|
||||||
|
|
||||||
|
- **Author**: ali
|
||||||
|
|||||||
Reference in New Issue
Block a user