3.4 KiB
3.4 KiB
yunpan1 — 获取资源
使用 Playwright 浏览器完成搜索、查看帖子、回复获取隐藏链接。
验证码
网站有时弹窗要求输入验证码。检测到输入框时填入:
// 第一步:填入验证码
await page.evaluate(() => {
const input = document.querySelector('input[placeholder*="验证码"]');
if (input) {
input.value = '392718';
input.dispatchEvent(new Event('input', { bubbles: true }));
input.dispatchEvent(new Event('change', { bubbles: true }));
}
});
// 第二步:点击提交按钮
await page.evaluate(() => {
let target = null;
document.querySelectorAll('button').forEach(b => {
if (b.textContent.includes('提交')) target = b;
});
if (target) target.click();
});
// 第三步:弹窗可能不自动消失,导航到板块页面即可
await page.goto('https://yunpan1.cc/forum.php?mod=forumdisplay&fid=3');
await page.waitForTimeout(2000);
前置检查
浏览器可能已登录 yunpan1,先检查登录状态:
const text = await page.evaluate(() => document.body.innerText);
const loggedIn = !text.includes('登录发现更多内容');
未登录时先登录(账号密码一般都保存在 skill 的 tmp 目录下):
await page.goto('https://yunpan1.cc/member.php?mod=logging&action=login');
await page.locator('form[name="login"] input[name="username"]').fill('账号');
await page.locator('form[name="login"] input[name="password"]').fill('密码');
await page.locator('form[name="login"] button[name="loginsubmit"]').click();
搜索
await page.goto('https://yunpan1.cc/search.php?mod=forum&srchtxt=' + encodeURIComponent('关键词') + '&searchsubmit=yes');
await page.waitForTimeout(3000);
const data = await page.evaluate(() => {
const text = document.body.innerText;
const links = text.match(/https?:\/\/pan\.quark\.cn\/s\/[a-zA-Z0-9]+/g) || [];
const threads = Array.from(document.querySelectorAll('a[href*="viewthread"]'));
const titles = threads.map(a => ({ title: a.innerText.trim(), url: a.href }));
return {
links: [...new Set(links)],
threads: [...new Map(titles.filter(t => t.title.length > 5).map(t => [t.title, t])).values()]
};
});
查看帖子详情
截断的链接需打开帖子查看。帖子有回复可见机制时,先回复再刷新:
// 打开帖子
await page.goto('帖子URL');
await page.waitForTimeout(2000);
// 检测是否有隐藏内容
const hasHidden = await page.evaluate(() =>
document.body.innerText.includes('本内容被作者隐藏')
);
if (hasHidden) {
// 点击回复按钮
await page.getByRole('link', { name: '回复', exact: true }).first().click();
await page.waitForTimeout(1000);
// 填写回复内容
await page.locator('#postmessage').fill('谢谢分享');
// 提交回复
await page.locator('button[name="replysubmit"]').first().click();
await page.waitForTimeout(3000);
// 刷新页面查看完整内容
await page.goto('帖子URL');
await page.waitForTimeout(2000);
}
// 提取夸克链接
const links = await page.evaluate(() => {
const text = document.body.innerText;
return [...new Set(text.match(/https?:\/\/pan\.quark\.cn\/s\/[a-zA-Z0-9]+/g) || [])];
});
板块浏览
搜索不可用时直接看动漫板块最新帖子:
https://yunpan1.cc/forum.php?mod=forumdisplay&fid=3&orderby=dateline
拿到链接后的操作
夸克链接转存流程见 storage/quark/v1/usage.md