Closed JHB-L closed 5 months ago
测试了一下,好像就国内专利保存不了,不确定是否和网络环境有关。
还有就是可否加入这个pdf下载功能,保存pdf附件。测试的外国专利保存正常,但全是屏幕快照的形式
@JHB-L 网站的 PDF 下载使用 POST 请求来获取文件,相关参数由网页自身维护(基本上,当你搜索出来的时候就在内部确定了),这些参数难以从外部获取。目前无法在 translator 中实现连同 PDF附件抓取,你只能手动下载PDF。
不过我注意到下载的PDF文件名有规律,基于此为你编写了实用的代码来导入这些手动下载的 PDF,使用步骤如下:
downloadDir
的值替换为你的下载路径,勾选“Run as async function”,然后点击窗口左上角的“Run”按钮来运行代码。const debug = [];
// 设置下载目录
const downloadDir = "C:\\test\\";
debug.push(`use ${downloadDir} as root dir`);
const patents = ZoteroPane.getSelectedItems().filter(item => item.itemType == "patent");
let pdfs = [];
await Zotero.File.iterateDirectory(
downloadDir,
async (child) => {
if (!child.isDir && /\.pdf$/i.test(child.name)) {
pdfs.push(child);
}
}
);
for (const item of patents) {
const msg = [];
msg.push(`process item: ${item.getDisplayTitle()}`);
let patentNumber = item.getField("patentNumber");
if (!patentNumber || Zotero.Items.get(item.getAttachments()).some(attachment => attachment.isPDFAttachment())) {
msg.push(`skip.`);
continue;
};
for (pdf of pdfs) {
const basename = pdf.name.slice(0, -4);
const theSame = basename == patentNumber;
// 不要使用.includes(),否则文件名很短时可能导致意外的匹配
const include = new RegExp(`^${basename};\s?|;\s?${basename}$|;\s?${basename};\s?`).test(patentNumber);
msg.push(`patent number: ${patentNumber} = base name: ${basename}? ${theSame}`);
msg.push(`patent number: ${patentNumber} in base name: ${basename}? ${include}`);
if (theSame || include) {
await Zotero.Attachments.importFromFile({
file: pdf.path,
libraryID: item.libraryID,
parentItemID: item.id
});
pdfs = pdfs.filter(file => file != pdf);
msg.push( `add attachment: ${pdf.name}. `);
// 在下一行的前面输入两个“/”,即可避免匹配附件的同时删除本地的 PDF 文件
Zotero.File.pathToFile(pdf.path).remove(true);
msg.push( `remove file: ${pdf.path}. `);
break;
}
}
if (!Zotero.Items.get(item.getAttachments()).some(attachment => attachment.isPDFAttachment())) {
msg.push(`no attachment matched.`);
};
debug.push(msg.join("\n"));
};
return debug.join("\n\n");
@jiaojiaodubai 非常感谢
你遇到了什么问题? [必填]
发生问题的链接 [必填] 国家知识产权局专利检索及分析系统
问题描述 [必填] 浏览器可识别条目,保存时报错
你的预期结果 可以保存相关条目及pdf附件
浏览器
自查清单
附件 Connector报错记录: