mcpField
C
cnki-search

cnki-search

github.com/cookjohn生产力1.0k1.2k 次安装33 周前更新
代码仓库

关于 cnki-search

通过浏览器按中文或英文关键词搜索 CNKI 论文的技能。它返回结果数量和结构化论文信息,并支持后续直达论文或批量导出到 Zotero。

主要功能

  1. 01按关键词搜索 CNKI
  2. 02返回数量和论文元数据
  3. 03直接打开论文页面
  4. 04批量导出结果到 Zotero

适用场景

  1. 01查找某个研究主题的论文
  2. 02查看结果中的作者、期刊和日期
  3. 03从搜索结果打开指定论文
  4. 04将搜索结果批量保存到 Zotero

MCP 相关

使用 Chrome DevTools 浏览器工具导航并搜索 CNKI。这是一个技能,而非 MCP 服务。

安装

复制下面的命令,在终端中运行。

$npx skills add https://github.com/cookjohn/cnki-skills --skill cnki-search

安装后在 Claude Code 中输入/cnki-search确认已加载。

详细介绍

CNKI 基本搜索

使用关键词搜索 CNKI 中的论文。一次调用即可返回结果数量和结构化结果列表(标题、URL、作者、期刊、日期)。

参数

$ARGUMENTS 包含中文或英文搜索关键词。

步骤

1. 导航

使用 mcp__chrome-devtools__navigate_page → https://kns.cnki.net/kns8s/search

2. 搜索并提取结果(单次 evaluate_script,不要使用 wait_for)

将 YOUR_KEYWORDS 替换为实际搜索词:

async () => {
  const query = "YOUR_KEYWORDS";

  // Wait for search input (replaces wait_for)
  await new Promise((r, j) => {
    let n = 0;
    const c = () => { if (document.querySelector('input.search-input')) r(); else if (++n > 30) j('timeout'); else setTimeout(c, 500); };
    c();
  });

  // Check captcha (only if visible on screen, not hidden SDK at top:-1000000)
  const outer = document.querySelector('#tcaptcha_transform_dy');
  if (outer && outer.getBoundingClientRect().top >= 0) return { error: 'captcha' };

  // Fill and submit (verified selectors: input.search-input, input.search-btn)
  const input = document.querySelector('input.search-input');
  input.value = query;
  input.dispatchEvent(new Event('input', { bubbles: true }));
  document.querySelector('input.search-btn')?.click();

  // Wait for results
  await new Promise((r, j) => {
    let n = 0;
    const c = () => { if (document.body.innerText.includes('条结果')) r(); else if (++n > 30) j('timeout'); else setTimeout(c, 500); };
    c();
  });

  // Check captcha again
  const outer2 = document.querySelector('#tcaptcha_transform_dy');
  if (outer2 && outer2.getBoundingClientRect().top >= 0) return { error: 'captcha' };

  // Extract current page results (merged parse-results)
  const rows = document.querySelectorAll('.result-table-list tbody tr');
  const checkboxes = document.querySelectorAll('.result-table-list tbody input.cbItem');
  const results = Array.from(rows).map((row, i) => {
    const titleLink = row.querySelector('td.name a.fz14');
    const authors = Array.from(row.querySelectorAll('td.author a.KnowledgeNetLink') || []).map(a => a.innerText?.trim());
    const journal = row.querySelector('td.source a')?.innerText?.trim() || '';
    const date = row.querySelector('td.date')?.innerText?.trim() || '';
    const citations = row.querySelector('td.quote')?.innerText?.trim() || '';
    const downloads = row.querySelector('td.download')?.innerText?.trim() || '';
    return {
      n: i + 1,
      title: titleLink?.innerText?.trim() || '',
      href: titleLink?.href || '',
      exportId: checkboxes[i]?.value || '',
      authors: authors.join('; '),
      journal,
      date,
      citations,
      downloads
    };
  });

  return {
    query,
    total: document.querySelector('.pagerTitleCell')?.innerText?.match(/([\d,]+)/)?.[1] || '0',
    page: document.querySelector('.countPageMark')?.innerText || '1/1',
    results
  };
}
3. 报告

将结果列为编号列表:

Searched CNKI for "$ARGUMENTS": found {total} results (page {page}).

1. {title}
   Authors: {authors} | Journal: {journal} | Date: {date}
   Citations: {citations} | Downloads: {downloads}

2. ...
4. 后续操作:导航至论文

当用户想要打开或下载特定论文时,直接使用结果中的 href URL 调用 navigate_page——不要点击链接(点击会打开新标签页,并浪费 3 次额外工具调用来管理标签页)。

验证码检测

检查 #tcaptcha_transform_dy 元素的 getBoundingClientRect().top >= 0。 腾讯验证码 SDK 会预加载 DOM,位置为 top: -1000000px(在屏幕外,未激活)。 只有当 top >= 0(用户实际可见)时,才返回 error: 'captcha'。

已验证的选择器

元素选择器说明
搜索框input.search-inputid=txt_search,placeholder "中文文献、外文文献"
搜索按钮input.search-btntype="button"
结果数量.pagerTitleCell文本 "共找到 X 条结果"
页码指示器.countPageMark文本 "1/300"
结果行.result-table-list tbody tr每一行对应一篇论文
标题链接td.name a.fz14论文标题及其 href
作者td.author a.KnowledgeNetLink作者姓名链接
期刊td.source a期刊/来源链接
日期td.date出版日期文本
引用次数td.quote引用次数
下载次数td.download下载次数

批量导出到 Zotero

当用户想要将结果保存到 Zotero 时,直接从结果页面批量导出——不要导航至每个详情页。结果中的 exportId 等于详情页的 #export-id。使用批量模式(步骤 1B)调用 cnki-export 技能。详情请参阅 cnki-export SKILL.md。

工具调用次数:2(navigate + evaluate_script)

评论

支持 Markdown