cnki-download

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

CNKI Paper Download (文献下载)

CNKI论文下载(文献下载)

Prerequisites

前置条件

User must be logged in to CNKI with download permissions.
用户必须已登录CNKI并拥有下载权限。

Arguments

参数

$ARGUMENTS
is optionally a paper detail URL. If blank, uses current page.
$ARGUMENTS
可选为论文详情页URL。若留空,则使用当前页面。

Steps

步骤

1. Navigate (if URL provided)

1. 跳转页面(若提供URL)

If URL provided: use
navigate_page
to go to the URL directly (no wait_for needed — Step 2 handles waiting).
Important: Always use
navigate_page
instead of clicking links on the search results page. Clicking opens a new tab and wastes 3 extra tool calls (
list_pages
+
select_page
+
take_snapshot
).
若提供了URL:直接使用
navigate_page
跳转至该URL(无需等待——步骤2会处理等待逻辑)。
重要提示:请始终使用
navigate_page
,而非点击搜索结果页的链接。点击链接会打开新标签页,并额外消耗3次工具调用(
list_pages
+
select_page
+
take_snapshot
)。

2. Check status and download (single async evaluate_script)

2. 检查状态并下载(单次异步evaluate_script调用)

Replace
FORMAT
with
"pdf"
or
"caj"
:
javascript
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 };
}
FORMAT
替换为
"pdf"
"caj"
javascript
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. Report

3. 结果反馈

Based on JS result:
  • status: downloading
    → "PDF 下载已触发:{title}。请在 Chrome 下载管理器中查看。"
  • error: not_logged_in
    → tell user to log in
  • error: captcha
    → tell user to solve captcha
根据JavaScript执行结果:
  • status: downloading
    → 「PDF下载已触发:{title}。请在Chrome下载管理器中查看。」
  • error: not_logged_in
    → 告知用户需要登录
  • error: captcha
    → 告知用户需要完成验证码验证

Tool calls: 1–2 (navigate_page if URL + evaluate_script)

工具调用次数:1–2次(若提供URL则调用navigate_page + evaluate_script)

Verified selectors

已验证的选择器

ElementSelectorNotes
PDF download
#pdfDown
<a>
inside
li.btn-dlpdf
CAJ download
#cajDown
<a>
inside
li.btn-dlcaj
Download area
.download-btns
parent
<div>
Not logged in
.downloadlink.icon-notlogged
Title
.brief h1
strip trailing "网络首发"
元素选择器说明
PDF下载按钮
#pdfDown
li.btn-dlpdf
内的
<a>
标签
CAJ下载按钮
#cajDown
li.btn-dlcaj
内的
<a>
标签
下载区域
.download-btns
父级
<div>
元素
未登录状态
.downloadlink.icon-notlogged
论文标题
.brief h1
移除末尾的「网络首发」字样

Captcha detection

验证码检测

Check
#tcaptcha_transform_dy
element's
getBoundingClientRect().top >= 0
. Only active when
top >= 0
(visible). Pre-loaded SDK sits at
top: -1000000px
.
检查
#tcaptcha_transform_dy
元素的
getBoundingClientRect().top >= 0
属性。 仅当
top >= 0
(元素可见)时,验证码处于激活状态。预加载的SDK默认位于
top: -1000000px
位置。