WoS Export Skill
通过 CloakBrowser 隐身 Chromium 浏览器,自动从 Web of Science 批量导出搜索结果为 Excel(Full Record)。
适用场景
- 需要从 WoS 搜索结果页批量导出大量记录(>1000 条)
- WoS 手动导出操作繁琐,需要自动化
- 需要绕过 WoS 的反自动化检测(CAPTCHA 等)
不适用场景
- 仅需导出少量记录(<1000 条,可手动完成)
- 没有可用的 SOCKS5 代理
- 没有有效的 WoS 搜索结果页 URL
前置条件
CloakBrowser:隐身 Chromium 浏览器,自动绕过反自动化检测
pip install cloakbrowser首次运行会自动下载 Chromium 二进制文件。如果网络受限,可设置代理:
# Windows (PowerShell) $env:HTTPS_PROXY = "socks5h://127.0.0.1:7890" python -c "import cloakbrowser; cloakbrowser.ensure_binary()"Python 依赖:
pip install pandas xlrd openpyxl本地代理:需要 SOCKS5 代理(默认
socks5://127.0.0.1:7890)用于访问 WoSWoS 搜索结果 URL:从 Clarivate China (
webofscience.clarivate.cn) 获取的搜索结果页 URL
核心技术要点
1. 所有交互通过 page.evaluate() JS DOM 操作
WoS 页面有 OneTrust cookie 叠加层,会拦截 Playwright 定位器的指针事件。所有点击操作必须通过 JavaScript DOM 操作完成。
2. Cookie 持久化
首次运行时接受 OneTrust cookie 并保存,后续运行自动加载,避免重复操作。
3. WoS 每批最多导出 1000 条
这是 WoS 的硬性限制。脚本自动分批处理。
4. 下载捕获
使用 page.expect_download() 捕获 XLS 下载事件,直接保存到指定目录。
快速开始
# 导出 20000 条搜索结果,每批 1000 条
python scripts/wos_batch_export.py \
--url "https://webofscience.clarivate.cn/wos/woscc/summary/..." \
--total 20000
# 跳过已下载的批次(断点续传)
python scripts/wos_batch_export.py \
--url "https://..." \
--total 20000 \
--skip-existing
# 仅合并已下载的 XLS 文件
python scripts/wos_batch_export.py --merge-only --url dummy --total 1
导出流程
启动 CloakBrowser(headless=True, proxy="socks5://127.0.0.1:7890")
→ 加载已保存的 Cookie(如有)
→ 导航到 WoS 搜索结果 URL
→ 接受 OneTrust Cookie: JS click #onetrust-accept-btn-handler
→ 保存 Cookie
→ 循环每批:
→ JS click #export-trigger-btn(打开导出菜单)
→ JS click "Excel"(选择 Excel 格式)
→ JS click #radio3-input(选择"Records from:"范围)
→ JS fill input[name='markFrom'] 和 input[name='markTo']
→ JS click Full Record 下拉选择
→ JS click #exportButton → 捕获下载事件
→ 保存为 {start}-{end}.xls
→ 合并所有 XLS 为 merged_wos_full_record.xlsx
JS 点击模式参考
所有 WoS 交互必须使用 page.evaluate() 进行 DOM 操作,不要使用 Playwright 定位器。
# 接受 Cookie
page.evaluate("() => document.getElementById('onetrust-accept-btn-handler').click()")
# 打开导出菜单
page.evaluate("() => document.getElementById('export-trigger-btn').click()")
# 点击 Excel 菜单项(文本匹配)
page.evaluate("""() => {
const items = document.querySelectorAll('*');
for (const el of items) {
if (el.innerText && el.innerText.trim() === 'Excel'
&& el.offsetParent !== null && el.children.length === 0) {
el.click(); return;
}
}
}""")
# 选择 "Records from:" 单选按钮
page.evaluate("() => document.getElementById('radio3-input').click()")
# 填充范围(使用 execCommand 兼容 Angular 响应式表单)
page.evaluate("""(from_val, to_val) => {
const from = document.querySelector("input[name='markFrom']");
const to = document.querySelector("input[name='markTo']");
if (from) { from.focus(); from.value = ''; document.execCommand('insertText', false, from_val); }
if (to) { to.focus(); to.value = ''; document.execCommand('insertText', false, to_val); }
}""", str(start), str(end))
# 选择 Full Record
page.evaluate("() => document.querySelector(\"button[aria-label*='Filter by']\")?.click()")
page.evaluate("""() => {
const items = document.querySelectorAll('span, mat-option, [role="option"]');
for (const item of items) {
if (item.innerText.trim() === 'Full Record') { item.click(); return; }
}
}""")
# 最终导出
page.evaluate("() => document.getElementById('exportButton').click()")
命令行参数
| 参数 | 说明 | 默认值 |
|---|---|---|
--url |
WoS 搜索结果页 URL | 必填 |
--total |
总记录数 | 必填 |
--batch-size |
每批记录数 | 1000 |
--start |
起始记录编号 | 1 |
--skip-existing |
跳过已下载的批次 | 否 |
--merge-only |
仅合并已有 XLS 文件 | 否 |
输出文件结构
wos-export/
├── SKILL.md # 本文件
├── scripts/
│ └── wos_batch_export.py # 批量导出脚本
├── README.md # GitHub 说明
├── requirements.txt # Python 依赖
└── example_output/
├── cookies.json # 保存的 WoS Cookie(示例)
└── downloads/
├── 1-1000.xls
├── 1001-2000.xls
├── ...
└── merged_wos_full_record.xlsx
注意事项
- 代理必须可用:CloakBrowser 启动时需要 SOCKS5 代理,确保代理正在运行
- WoS URL 有效期:搜索结果 URL 会过期,获取后尽快使用
- 下载超时:如果某批下载超时,脚本会标记为 FAIL 并继续下一批。使用
--skip-existing可以重跑失败批次 - 合并需要 xlrd:WoS 导出的 XLS 是真正的 Excel 二进制格式(不是 HTML),合并需要
xlrd库 - CloakBrowser 版本:建议 >= 0.3.30,旧版本可能缺少 Chromium 二进制文件
常见问题
Q: 为什么不能用 Playwright 定位器? A: WoS 页面有 OneTrust cookie 同意弹窗,这个叠加层会拦截所有指针事件。只有 JS DOM 操作能绕过它。
Q: 为什么 execCommand('insertText') 而不是直接赋值?
A: WoS 使用 Angular 框架的响应式表单,直接赋值 input.value 不会触发 Angular 的变更检测。execCommand('insertText') 模拟用户输入,能正确触发框架更新。
Q: 导出超时怎么办?
A: 默认每批 120 秒超时。如果超时,脚本会继续下一批。完成后用 --skip-existing 重跑失败的批次。