交易相关博主和up主

  • 项目目的: 记录下交易和量化相关的up主们
下载up主所有视频
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
// 获取所有匹配的元素
const elements = document.querySelectorAll('div.info__top a.title');

// 将每个元素转换为所需的格式
const result = Array.from(elements)
.map(element => `biliv "${element.href}"`)
.join('\n');

// 创建临时textarea元素来复制文本
const textarea = document.createElement('textarea');
textarea.value = result;
document.body.appendChild(textarea);
textarea.select();

// 执行复制命令
document.execCommand('copy');

// 移除临时元素
document.body.removeChild(textarea);

// 输出结果数量供确认
console.log(`已复制 ${elements.length} 个链接到剪贴板`);
1
2
// 下载某个合集时修改上面选取条件
document.querySelectorAll('.bili-video-card__title a')
爬取up主所有视频
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
// 存储所有结果
let allResults = [];

async function scrapeAllPages() {
try {
// 初始页面
await scrapeCurrentPage();

// 循环翻页
while (await goToNextPage()) {
await scrapeCurrentPage();
}

// 完成后的处理
await showFinalResults();

} catch (error) {
console.error('出错:', error);
alert(`爬取中断: ${error.message}`);
}
}

// 爬取当前页数据
function scrapeCurrentPage() {
return new Promise(resolve => {
setTimeout(() => {
const elements = document.querySelectorAll('div.info__top a.title');
const pageResults = Array.from(elements).map(el => `biliv "${el.href}"`);

allResults = [...allResults, ...pageResults];
console.log(`[进度] 当前页: ${pageResults.length}条 | 总计: ${allResults.length}条`);
resolve();
}, 1000);
});
}

// 跳转到下一页
function goToNextPage() {
return new Promise(resolve => {
setTimeout(() => {
const buttons = [...document.querySelectorAll('button.vui_button')];
const nextBtn = buttons.find(btn =>
/下一页|下一頁|>|»/.test(btn.textContent.trim()) && !btn.disabled
);

if (nextBtn) {
console.log('[动作] 正在跳转下一页...');
nextBtn.click();
setTimeout(resolve, 2500, true); // 等待页面加载
} else {
console.log('[状态] 已是最后一页');
resolve(false);
}
}, 500);
});
}

// 最终结果处理
async function showFinalResults() {
const resultText = allResults.join('\n');
console.log(`[完成] 共爬取 ${allResults.length} 条数据:\n${resultText}`);

// 创建可视化复制界面
const div = document.createElement('div');
div.style = `
position: fixed; top: 20px; right: 20px; z-index: 99999;
padding: 15px; background: #fff; box-shadow: 0 0 10px rgba(0,0,0,0.3);
border-radius: 5px; font-family: sans-serif; max-width: 300px;
`;

div.innerHTML = `
<h3 style="margin-top:0">爬取完成</h3>
<p>共 ${allResults.length} 条数据</p>
<textarea id="result-data" style="width:100%; height:100px; margin:10px 0">${resultText}</textarea>
<button id="copy-btn" style="padding:8px 15px; background:#07c; color:#fff; border:none; border-radius:4px">
点击复制
</button>
<button id="close-btn" style="margin-left:10px; padding:8px 15px">关闭</button>
`;

document.body.appendChild(div);

// 添加按钮事件
div.querySelector('#copy-btn').addEventListener('click', async () => {
try {
await navigator.clipboard.writeText(resultText);
alert('已成功复制到剪贴板!');
} catch (err) {
const textarea = div.querySelector('#result-data');
textarea.select();
document.execCommand('copy');
alert('已使用备用方法复制!');
}
});

div.querySelector('#close-btn').addEventListener('click', () => {
div.remove();
});
}

// 开始执行
scrapeAllPages();
  • @海豹豹游来游去
  • @jim做交易
  • @野生量化员
  • @BigQuant量化投资