关于 gs-export
这是一项将 Google Scholar 引文数据导出到 Zotero 的 Claude 技能,也可附加搜索结果中的 PDF。支持单篇和批量处理。
主要功能
- 01从 Google Scholar 提取 BibTeX
- 02解析引文字段并写入 Zotero
- 03使用搜索结果链接添加 PDF
- 04批量导出论文
适用场景
- 01将 Google Scholar 引文存入 Zotero
- 02批量导入论文到 Zotero
- 03附加可获取的论文 PDF
MCP 相关
该技能使用 Chrome DevTools MCP 工具获取 BibTeX 并浏览 Google Scholar,随后调用 Python 脚本将记录发送到 Zotero。
安装
复制下面的命令,在终端中运行。
npx skills add https:/ / github.com/ cookjohn/ gs-skills --skill gs-export安装后在 Claude Code 中输入/gs-export确认已加载。
附带文件scripts/push_to_zotero.py
详细介绍
将 Google Scholar 导出到 Zotero
通过提取 BibTeX 导出 Google Scholar 论文引用数据,并推送到 Zotero 桌面版。
参数
$ARGUMENTS 包含一个或多个 data-cid(以空格分隔),例如:
TFS2GgoGiNUJ— 单篇论文TFS2GgoGiNUJ abc123XYZ def456UVW— 批量导出
步骤
步骤 1:获取每篇论文的 BibTeX
对每个 data-cid,执行 3 次工具调用以绕过 CORS:
1a. 获取引用对话框以取得 BibTeX 链接(evaluate_script)
async () => {
const cid = "DATA_CID_HERE";
const resp = await fetch(
`https://scholar.google.com/scholar?q=info:${cid}:scholar.google.com/&output=cite`,
{ credentials: 'include' }
);
const html = await resp.text();
const doc = new DOMParser().parseFromString(html, 'text/html');
// Extract export links
const links = Array.from(doc.querySelectorAll('#gs_citi a')).map(a => ({
format: a.textContent.trim(),
url: a.href
}));
// Extract citation format texts
const citations = Array.from(doc.querySelectorAll('#gs_citt tr')).map(tr => {
const cells = tr.querySelectorAll('td');
return {
style: cells[0]?.textContent?.trim() || '',
text: cells[1]?.textContent?.trim() || ''
};
});
const bibtexLink = links.find(l => l.format === 'BibTeX');
return { cid, bibtexLink: bibtexLink?.url || '', links, citations };
}
1b. 导航到 BibTeX URL(navigate_page)
使用 mcp__chrome-devtools__navigate_page:
- url:步骤 1a 中的
bibtexLinkURL(位于scholar.googleusercontent.com)
这会绕过阻止向 googleusercontent.com 发起 fetch() 请求的 CORS 限制。
1c. 读取 BibTeX 内容(evaluate_script)
async () => {
return { bibtex: document.body.innerText || document.body.textContent || '' };
}
步骤 2:解析 BibTeX 并推送到 Zotero
将 BibTeX 数据保存为 JSON,然后调用推送脚本:
python "E:/gscholar-skills/.claude/skills/gs-export/scripts/push_to_zotero.py" /tmp/gs_papers.json
调用脚本之前,在 /tmp/gs_papers.json 创建一个 JSON 文件,其中包含从 BibTeX 解析出的论文数据。自行解析 BibTeX 并创建 JSON 数组:
[
{
"pmid": "",
"title": "The title from BibTeX",
"authors": [
{"lastName": "Smith", "firstName": "John"}
],
"journal": "Journal Name",
"journalAbbr": "",
"pubdate": "2022",
"volume": "14",
"issue": "4",
"pages": "1054",
"doi": "",
"pdfUrl": "https://example.com/paper.pdf",
"abstract": "",
"keywords": [],
"language": "en",
"pubtype": ["Journal Article"]
}
]
重要:将 pdfUrl 设为搜索结果的 fullTextUrl 字段(由 gs-search 提取的 PDF 链接)。Python 脚本会下载 PDF,并通过 /connector/saveAttachment 上传到 Zotero(Zotero 7.x 会忽略 saveItems 中的附件)。部分出版商的 PDF 下载可能会失败(403、JS 重定向);这些情况会报告为“PDF skip”。
BibTeX 字段映射:
@article{key,→itemType: journalArticle@inproceedings{key,→itemType: conferencePaper@book{key,→itemType: booktitle={...}→titleauthor={Last1, First1 and Last2, First2}→authors数组journal={...}→journalyear={...}→pubdatevolume={...}→volumenumber={...}→issuepages={...}→pagespublisher={...}→(包含在 extra 或 publisher 字段中)
步骤 3:报告
单篇论文:
Exported to Zotero from Google Scholar:
Title: {title}
Authors: {authors}
Journal: {journal} ({year})
Data-CID: {dataCid}
批量:
Exported {count} papers to Zotero from Google Scholar:
1. {title1} ({journal1}, {year1})
2. {title2} ({journal2}, {year2})
...
批量导出优化
导出多篇论文时,按顺序处理以避免触发 CAPTCHA:
- 在一次 evaluate_script 调用中获取所有 BibTeX 链接(获取所有引用对话框)
- 逐个导航到各个 BibTeX URL
- 收集所有 BibTeX 条目
- 将所有条目一次性批量推送到 Zotero
注意事项
- 导出单篇论文需要 3–4 次工具调用:
evaluate_script(引用对话框)+navigate_page(BibTeX URL)+evaluate_script(读取 BibTeX)+bash python(推送到 Zotero) - 批量导出:2N+1 次工具调用(N 篇论文:N 次 navigate + N 次 evaluate + 1 次 bash)
- BibTeX 链接位于
scholar.googleusercontent.com— CORS 会阻止 fetch(),因此我们使用 navigate_page 绕过限制 - 复用
push_to_zotero.py与 Zotero Connector API 通信 - Google Scholar BibTeX 不包含摘要或 DOI — 这些字段在 Zotero 中会留空
- 导出后,导航回 Google Scholar 页面:使用 type 为
back的navigate_page