灵猴市集Linghou Market

万方数据论文搜索

万方数据wanfang-paper-search

用途 读取当前万方数据论文搜索结果页,返回论文标题、作者、来源、年份、类型、被引次数和详情页地址。 执行前提 请先打开万方数据论文搜索结果页,例如 https://s.wanfangdata.com.cn/paper?q=人工智能。脚本读取当前页面 DOM。若网站出现验证码、安全验证或访问频率限制,需要先在真实浏览器会话中确认状态后再重试。 参数 quer…

论文搜索文献
版本1.0.0
扫描passed
更新2026-06-28
超时30000ms

匹配范围

*://s.wanfangdata.com.cn/*

排除范围

未声明

能力声明

dom.read

代码

源码已展开
1return await (async () => {2  const input = params && typeof params === "object" ? params : {};3  const clean = (value) => String(value == null ? "" : value).replace(/\s+/g, " ").trim();4  const expectedQuery = clean(input.query || input.q || input.keyword);5  const rawLimit = input.limit == null || input.limit === "" ? 10 : input.limit;6  const limit = typeof rawLimit === "number" ? rawLimit : Number(String(rawLimit).trim());7  if (!Number.isInteger(limit) || limit < 1 || limit > 20) {8    throw new Error("limit 必须是 1 到 20 之间的整数。");9  }10 11  if (!/wanfangdata\.com\.cn$/.test(location.hostname) || !/\/paper/.test(location.pathname)) {12    throw new Error("请先打开万方数据论文搜索结果页,例如 https://s.wanfangdata.com.cn/paper?q=人工智能。");13  }14 15  const pageText = clean(document.body?.innerText || "");16  const titleNodes = Array.from(document.querySelectorAll("span.title"));17  if (titleNodes.length === 0 && /验证码|安全验证|访问过于频繁|异常访问/.test(pageText)) {18    throw new Error("万方数据搜索页可能出现验证码或访问频率限制,请在真实浏览器会话中确认后重试。");19  }20 21  const results = [];22  for (const titleSpan of titleNodes) {23    const title = clean(titleSpan.textContent);24    if (!title || title.length < 3) continue;25 26    let container = titleSpan.parentElement;27    for (let i = 0; i < 8; i += 1) {28      if (!container?.parentElement || container.parentElement.tagName === "BODY") break;29      const text = clean(container.textContent || "");30      if (container.querySelectorAll("span.title").length >= 1 && (container.querySelectorAll("span.authors").length >= 1 || /\[.+?\]/.test(text))) break;31      container = container.parentElement;32    }33    if (!container) continue;34 35    const text = clean(container.textContent || "");36    const id = clean(container.querySelector("span.title-id-hidden")?.textContent);37    const authors = Array.from(container.querySelectorAll("span.authors"))38      .map((item) => clean(item.textContent))39      .filter(Boolean)40      .join(", ")41      .slice(0, 100);42    const source = clean(container.querySelector("span.periodical, span.source")?.textContent)43      || clean((text.match(/《([^》]+)》/) || [])[1]);44    let year = clean(container.querySelector("span.year, span.date")?.textContent);45    if (!year) year = (text.match(/(19|20)\d{2}/) || [])[0] || "";46    const type = clean(container.querySelector("span.essay-type")?.textContent)47      || clean((text.match(/\[(.+?)\]/) || [])[1]);48    const citedText = clean(container.querySelector('.stat-item.quote, [class*="quote"]')?.textContent);49    const cited = (citedText.match(/(\d+)/) || [])[1] || "";50    const href = titleSpan.closest("a[href]")?.href || container.querySelector("a[href]")?.href || "";51 52    results.push({53      rank: results.length + 1,54      title,55      authors,56      source,57      year,58      type,59      cited,60      url: href || (id ? `https://d.wanfangdata.com.cn/${id}` : ""),61    });62    if (results.length >= limit) break;63  }64 65  if (results.length === 0) {66    throw new Error("没有从当前万方数据搜索结果页提取到论文结果,请确认页面已加载完成。");67  }68 69  return {70    query: expectedQuery || new URLSearchParams(location.search).get("q") || "",71    sourceUrl: location.href,72    count: results.length,73    items: results,74  };75})();