关于 cnki-download
cnki-download 是用于从 CNKI 下载论文的技能,面向已登录且具有下载权限的用户。它可从当前页面或指定论文详情页触发 PDF 或 CAJ 下载,并检查登录与验证码状态。
主要功能
- 01从当前页或指定链接下载
- 02支持 PDF 与 CAJ 格式
- 03检测登录状态和验证码
- 04提取论文标题
适用场景
- 01下载 CNKI 论文全文
- 02确认下载前是否需要登录
- 03处理页面上的验证码提示
安装
复制下面的命令,在终端中运行。
$
npx skills add https:/ / github.com/ cookjohn/ cnki-skills --skill cnki-download安装后在 Claude Code 中输入/cnki-download确认已加载。
详细介绍
CNKI 论文下载(文献下载)
前提条件
用户必须已登录 CNKI,且拥有下载权限。
参数
$ARGUMENTS 是可选的论文详情页 URL。如果为空,则使用当前页面。
步骤
1. 导航(如果提供了 URL)
如果提供了 URL:使用 navigate_page 直接前往该 URL(无需调用 wait_for——步骤 2 会处理等待)。
重要提示:始终使用 navigate_page,不要点击搜索结果页上的链接。点击会打开新标签页,并多消耗 3 次工具调用(list_pages + select_page + take_snapshot)。
2. 检查状态并下载(单次异步 evaluate_script)
将 FORMAT 替换为 "pdf" 或 "caj":
async () => {
// Wait for page load
await new Promise((r, j) => {
let n = 0;
const c = () => {
if (document.querySelector('.brief h1')) r();
else if (++n > 30) j('timeout');
else setTimeout(c, 500);
};
c();
});
// Captcha check
const cap = document.querySelector('#tcaptcha_transform_dy');
if (cap && cap.getBoundingClientRect().top >= 0) {
return { error: 'captcha', message: 'CNKI 正在显示滑块验证码。请在 Chrome 中手动完成拼图验证。' };
}
const format = "FORMAT"; // "pdf" or "caj"
// Check download links
const pdfLink = document.querySelector('#pdfDown') || document.querySelector('.btn-dlpdf a');
const cajLink = document.querySelector('#cajDown') || document.querySelector('.btn-dlcaj a');
// Check login status
const notLogged = document.querySelector('.downloadlink.icon-notlogged')
|| document.querySelector('[class*="notlogged"]');
if (notLogged) {
return { error: 'not_logged_in', message: '下载需要登录。请先在 Chrome 中登录知网账号。' };
}
const title = document.querySelector('.brief h1')?.innerText?.trim()?.replace(/\s*网络首发\s*$/, '') || '';
if (format === 'pdf' && pdfLink) {
pdfLink.click();
return { status: 'downloading', format: 'PDF', title };
} else if (format === 'caj' && cajLink) {
cajLink.click();
return { status: 'downloading', format: 'CAJ', title };
} else if (pdfLink) {
pdfLink.click();
return { status: 'downloading', format: 'PDF', title };
} else if (cajLink) {
cajLink.click();
return { status: 'downloading', format: 'CAJ', title };
}
return { error: 'no_download', message: '未找到下载链接', hasPDF: !!pdfLink, hasCAJ: !!cajLink };
}
3. 报告结果
根据 JS 结果:
status: downloading→ “已触发 PDF 下载:{title}。请在 Chrome 下载管理器中查看。”error: not_logged_in→ 提示用户登录error: captcha→ 提示用户完成人机验证
工具调用:1–2 次(如果提供了 URL,则调用 navigate_page + evaluate_script)
已验证的选择器
| 元素 | 选择器 | 备注 |
|---|---|---|
| PDF 下载 | #pdfDown | li.btn-dlpdf 内的 <a> |
| CAJ 下载 | #cajDown | li.btn-dlcaj 内的 <a> |
| 下载区域 | .download-btns | 父级 <div> |
| 未登录 | .downloadlink.icon-notlogged | |
| 标题 | .brief h1 | 删除末尾的“网络首发” |
验证码检测
检查 #tcaptcha_transform_dy 元素的 getBoundingClientRect().top >= 0。
仅当 top >= 0(可见)时才处于活动状态。预加载的 SDK 位于 top: -1000000px。
评论
支持 Markdown