papersearch 0.5.0 → 0.5.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.en.md +35 -48
- package/README.md +35 -48
- package/carsi/paper_search_carsi/assets/api_keys.json +1 -1
- package/carsi/paper_search_carsi/assets/capsule_en.json +5 -0
- package/carsi/paper_search_carsi/browser/cookies.py +3 -206
- package/carsi/paper_search_carsi/cli.py +73 -37
- package/carsi/paper_search_carsi/config.py +24 -106
- package/carsi/paper_search_carsi/download_diagnostics.py +3 -3
- package/carsi/paper_search_carsi/engine/batch.py +15 -0
- package/carsi/paper_search_carsi/engine/batch_common.py +6 -0
- package/carsi/paper_search_carsi/engine/bridge.py +17 -4
- package/carsi/paper_search_carsi/orchestrator.py +19 -2
- package/dist/capabilities/pdf-discovery/carsi/CarsiAttempt.d.ts.map +1 -1
- package/dist/capabilities/pdf-discovery/carsi/CarsiAttempt.js +2 -0
- package/dist/capabilities/pdf-discovery/carsi/CarsiAttempt.js.map +1 -1
- package/dist/capabilities/pdf-discovery/carsi/CarsiMcpClient.js +1 -1
- package/dist/cli.js +25 -7
- package/dist/cli.js.map +1 -1
- package/dist/infrastructure/runlog/failureClass.d.ts.map +1 -1
- package/dist/infrastructure/runlog/failureClass.js +1 -0
- package/dist/infrastructure/runlog/failureClass.js.map +1 -1
- package/dist/management/carsi/login.d.ts +28 -0
- package/dist/management/carsi/login.d.ts.map +1 -0
- package/dist/management/carsi/login.js +46 -0
- package/dist/management/carsi/login.js.map +1 -0
- package/dist/management/skills/nextSteps.d.ts +3 -0
- package/dist/management/skills/nextSteps.d.ts.map +1 -1
- package/dist/management/skills/nextSteps.js +9 -3
- package/dist/management/skills/nextSteps.js.map +1 -1
- package/package.json +1 -1
- package/skills/paper-search/SKILL.md +12 -8
- package/skills/paper-search/references/browser-download.md +2 -1
- package/skills/paper-search/references/capability-routing.md +1 -1
- package/skills/paper-search/references/carsi-setup.md +14 -3
- package/skills/paper-search/references/cli-contract.md +1 -0
- package/skills/paper-search/references/publisher-support.md +1 -1
- package/carsi/paper_search_carsi/browser/login.py +0 -332
package/README.en.md
CHANGED
|
@@ -55,23 +55,23 @@ Please install PaperSearch: npm install -g papersearch, then run paper-search sk
|
|
|
55
55
|
|
|
56
56
|
It installs the command and the Skill, checks them, and tells you what already works.
|
|
57
57
|
|
|
58
|
-
### 2.
|
|
58
|
+
### 2. The school subscription downloads component installs automatically
|
|
59
59
|
|
|
60
|
-
|
|
60
|
+
On a computer, your AI installs the [school subscription downloads (CARSI)](#1-school-subscription-downloads-carsi) component automatically right after PaperSearch, and Chrome too if it is missing; when it is done, the settings window opens for step 3.
|
|
61
61
|
|
|
62
|
-
-
|
|
63
|
-
-
|
|
62
|
+
- Don't want it? Tell your AI and it is skipped for good; searching and open-access downloads work as before.
|
|
63
|
+
- Servers without a screen don't get it.
|
|
64
64
|
|
|
65
|
-
<p align="center"><img src="assets/install.en.webp" width="840" alt="Install demo: send your AI one sentence; it installs PaperSearch and the Skill, lists what works,
|
|
65
|
+
<p align="center"><img src="assets/install.en.webp" width="840" alt="Install demo: send your AI one sentence; it installs PaperSearch and the Skill, lists what works, then installs school subscription downloads (CARSI) automatically, Chrome first if it is missing, and opens the settings window"></p>
|
|
66
66
|
|
|
67
67
|
### 3. Add API keys when you need them
|
|
68
68
|
|
|
69
|
-
<p align="center"><img src="assets/config.en.webp" width="840" alt="Key demo: send a key to your AI and it saves and tests it;
|
|
69
|
+
<p align="center"><img src="assets/config.en.webp" width="840" alt="Key demo: send a key to your AI and it saves and tests it; once the school subscription downloads (CARSI) component is installed, set keys, the download folder and waiting times in the settings window"></p>
|
|
70
70
|
|
|
71
71
|
Get a key when you need that feature (sign-up pages: [API keys](#2-api-keys)) and enter it any of these ways:
|
|
72
72
|
|
|
73
73
|
- **Send it to your AI**: paste the key into the chat; it saves and tests it. The key stays in that conversation's history; if you'd rather not, use one of the other two ways.
|
|
74
|
-
- **Settings window** (
|
|
74
|
+
- **Settings window** (installed automatically with the school subscription downloads component): ask your AI to open the settings, or click the gear on the capsule. API keys, the download folder, waiting times and notifications are all there, and every key has a Test button.
|
|
75
75
|
- **Terminal**: run `paper-search setup <KEY>`; the input is hidden.
|
|
76
76
|
|
|
77
77
|
### 4. Tell your AI tool what you need
|
|
@@ -112,42 +112,12 @@ Feature comparison:
|
|
|
112
112
|
|  Subscription papers | — | ✅ (Elsevier, Springer) | ✅ (30+ major publishers) |
|
|
113
113
|
|  Supplementary files | — | — | ✅ |
|
|
114
114
|
| **You need** | Node.js 18 or later | Keys from each provider | Google Chrome, a school account |
|
|
115
|
-
| **How to turn it on** | Quick start step 1 |
|
|
115
|
+
| **How to turn it on** | Quick start step 1 | Settings window, your AI or terminal | Comes along on a computer |
|
|
116
116
|
|
|
117
117
|
### 1. School subscription downloads (CARSI)
|
|
118
118
|
|
|
119
119
|
Papers the open channels cannot get can come through your school's subscriptions. CARSI is the China higher-education identity federation; almost every Chinese university has joined it, so your school account signs you in to the publishers.
|
|
120
120
|
|
|
121
|
-
Install:
|
|
122
|
-
|
|
123
|
-
```bash
|
|
124
|
-
paper-search carsi install # choose your school during installation
|
|
125
|
-
paper-search carsi status --format text # check that it is ready
|
|
126
|
-
```
|
|
127
|
-
|
|
128
|
-
<table>
|
|
129
|
-
<tr>
|
|
130
|
-
<td width="50%" valign="top">
|
|
131
|
-
<img src="assets/carsi-capsule.en.webp" alt="Progress capsule: a small capsule shows the progress, hover for each paper, minimized to the Dock it keeps downloading, one click brings it back">
|
|
132
|
-
<p><b>Progress capsule</b></p>
|
|
133
|
-
</td>
|
|
134
|
-
<td width="50%" valign="top">
|
|
135
|
-
<img src="assets/carsi-signin.en.webp" alt="School sign-in: clicking the title brings the browser forward; the institution login is clicked, the school filled in, then on to the school's login page">
|
|
136
|
-
<p><b>School sign-in</b></p>
|
|
137
|
-
</td>
|
|
138
|
-
</tr>
|
|
139
|
-
<tr>
|
|
140
|
-
<td width="50%" valign="top">
|
|
141
|
-
<img src="assets/carsi-attention.en.webp" alt="Asks when needed: the capsule turns amber for the school login; click to switch to the browser, or skip the paper">
|
|
142
|
-
<p><b>Asks when needed</b></p>
|
|
143
|
-
</td>
|
|
144
|
-
<td width="50%" valign="top">
|
|
145
|
-
<img src="assets/carsi-finish.en.webp" alt="Results: skip a paper; the final card lists what was saved and why the rest wasn't; clicking a title opens it in your own browser">
|
|
146
|
-
<p><b>Results</b></p>
|
|
147
|
-
</td>
|
|
148
|
-
</tr>
|
|
149
|
-
</table>
|
|
150
|
-
|
|
151
121
|
- **Your school account is enough**: no keys to apply for; publisher API keys only cover Elsevier and Springer.
|
|
152
122
|
- **Deep publisher adaptation**: the general download flow is deeply optimized, and more than 30 publishers have dedicated rules, one by one: where the institutional login is and how to fetch the PDF and supplementary files follow each publisher as it really is, so downloads are more accurate and fewer papers are missed. The main publishers:
|
|
153
123
|
- General: Elsevier (including Cell and The Lancet), Springer Nature (including Nature and BMC), Wiley, Oxford Academic, Taylor & Francis, Sage, PNAS, Science
|
|
@@ -158,6 +128,33 @@ paper-search carsi status --format text # check that it is ready
|
|
|
158
128
|
- **Verification boxes clicked for you**: it finds and clicks human-verification boxes and carries on once the site lets it through; you are asked only when it does not pass.
|
|
159
129
|
- **Quiet background downloads**: the browser works in the background. The progress capsule in a screen corner shows the progress; it turns amber when you need to sign in or verify, one click switches to the browser, and the download carries on once you are done.
|
|
160
130
|
|
|
131
|
+
Install:
|
|
132
|
+
|
|
133
|
+
```bash
|
|
134
|
+
paper-search carsi install # choose your school during installation
|
|
135
|
+
paper-search carsi status --format text # check that it is ready
|
|
136
|
+
```
|
|
137
|
+
|
|
138
|
+
**Progress capsule**
|
|
139
|
+
|
|
140
|
+
<p align="center"><img src="assets/carsi-capsule.en.webp" width="840" alt="Progress capsule: a small capsule shows the progress, hover for each paper, minimized to the Dock it keeps downloading, one click brings it back"></p>
|
|
141
|
+
|
|
142
|
+
**Verification pages**
|
|
143
|
+
|
|
144
|
+
<p align="center"><img src="assets/carsi-verify.en.webp" width="840" alt="Verification pages: when a verification page stops the download, it passes on its own, no clicks from you"></p>
|
|
145
|
+
|
|
146
|
+
**School sign-in**
|
|
147
|
+
|
|
148
|
+
<p align="center"><img src="assets/carsi-signin.en.webp" width="840" alt="School sign-in: clicking the title brings the browser forward; the institution login is clicked, the school filled in, then on to the school's login page"></p>
|
|
149
|
+
|
|
150
|
+
**Asks when needed**
|
|
151
|
+
|
|
152
|
+
<p align="center"><img src="assets/carsi-attention.en.webp" width="840" alt="Asks when needed: the capsule turns amber for the school login; click to switch to the browser, or skip the paper"></p>
|
|
153
|
+
|
|
154
|
+
**Results**
|
|
155
|
+
|
|
156
|
+
<p align="center"><img src="assets/carsi-finish.en.webp" width="840" alt="Results: skip a paper; the final card lists what was saved and why the rest wasn't; clicking a title opens it in your own browser"></p>
|
|
157
|
+
|
|
161
158
|
### 2. API keys
|
|
162
159
|
|
|
163
160
|
Keys fall into four groups by what they are for. Get the key you need and enter it any of the ways in [Quick start step 3](#3-add-api-keys-when-you-need-them).
|
|
@@ -194,16 +191,6 @@ Keys fall into four groups by what they are for. Get the key you need and enter
|
|
|
194
191
|
| OpenAIRE | `OPENAIRE_API_KEY` | [OpenAIRE](https://develop.openaire.eu/) |
|
|
195
192
|
| OpenAlex (all citing papers past 10,000) | `OPENALEX_API_KEY` | [OpenAlex](https://openalex.org/settings/api) |
|
|
196
193
|
|
|
197
|
-
Common commands:
|
|
198
|
-
|
|
199
|
-
```bash
|
|
200
|
-
paper-search setup # the common settings, one by one
|
|
201
|
-
paper-search setup EASYSCHOLAR_KEY # just one of them
|
|
202
|
-
paper-search settings # with school subscription downloads: fill them in a window
|
|
203
|
-
paper-search config list --pretty # what is set; keys are masked
|
|
204
|
-
paper-search config test --format text # whether the keys you set work
|
|
205
|
-
```
|
|
206
|
-
|
|
207
194
|
Settings are saved in `~/.config/paper-search-cli/config.json`, readable only by you. The download folder, contact emails, proxy, automatic updates and other settings are in [Guide · Other settings](docs/guide.en.md#other-settings).
|
|
208
195
|
|
|
209
196
|
## More documentation
|
package/README.md
CHANGED
|
@@ -55,23 +55,23 @@ https://github.com/user-attachments/assets/7573a2a8-0778-4062-aa3e-4ccffb482b0b
|
|
|
55
55
|
|
|
56
56
|
它会装好命令和 Skill,自己检查一遍,告诉你哪些功能已经能用。
|
|
57
57
|
|
|
58
|
-
### 2.
|
|
58
|
+
### 2. 自动装好学校订阅下载组件
|
|
59
59
|
|
|
60
|
-
|
|
60
|
+
在电脑上,AI 装好 PaperSearch 后会自动装好[学校订阅下载(CARSI)](#1-学校订阅下载carsi)组件,本机没有 Chrome 时一起装好;装完自动弹出设置窗口,接着做第 3 步。
|
|
61
61
|
|
|
62
|
-
-
|
|
63
|
-
-
|
|
62
|
+
- 不想要的话跟 AI 说一声就跳过,之后不再提;检索和 OA 文章下载照常能用。
|
|
63
|
+
- 没有图形界面的服务器上不装。
|
|
64
64
|
|
|
65
|
-
<p align="center"><img src="assets/install.webp" width="840" alt="安装演示:把一句话发给 AI,它装好 PaperSearch 和 Skill
|
|
65
|
+
<p align="center"><img src="assets/install.webp" width="840" alt="安装演示:把一句话发给 AI,它装好 PaperSearch 和 Skill,列出能用的功能,再自动装好学校订阅下载(CARSI)组件,缺 Chrome 时先装 Chrome,装完弹出设置窗口"></p>
|
|
66
66
|
|
|
67
67
|
### 3. 按需填 API key
|
|
68
68
|
|
|
69
|
-
<p align="center"><img src="assets/config.webp" width="840" alt="填 key 演示:把 key 发给 AI
|
|
69
|
+
<p align="center"><img src="assets/config.webp" width="840" alt="填 key 演示:把 key 发给 AI,它替你保存并测试;自动装好学校订阅下载(CARSI)组件后,在设置窗口里填 key、改下载文件夹和等待时间"></p>
|
|
70
70
|
|
|
71
71
|
要用哪项再申请对应的 key(申请入口见 [API key](#2-api-key)),用下面任一方式填入:
|
|
72
72
|
|
|
73
73
|
- **发给 AI**:把 key 直接发给它,它替你保存并测试。key 会留在这次对话的记录里,不想这样就用下面两种方式。
|
|
74
|
-
-
|
|
74
|
+
- **设置窗口**(随学校订阅下载组件自动装好):让 AI 打开设置,或点胶囊上的齿轮。API key、下载文件夹、等待时间和提醒都在这里改,每个 key 都能点“测试”。
|
|
75
75
|
- **终端**:运行 `paper-search setup <KEY>`,输入时不显示。
|
|
76
76
|
|
|
77
77
|
### 4. 对 AI 说一句话
|
|
@@ -112,42 +112,12 @@ https://github.com/user-attachments/assets/7573a2a8-0778-4062-aa3e-4ccffb482b0b
|
|
|
112
112
|
|  下载非 OA 文章 | — | ✅(Elsevier、Springer) | ✅(30+主流出版社) |
|
|
113
113
|
|  下载补充材料 | — | — | ✅ |
|
|
114
114
|
| **需要准备** | Node.js 18 或以上 | 到各家网站申请 key | Google Chrome、学校账号 |
|
|
115
|
-
| **怎么开启** | 快速开始第 1 步 |
|
|
115
|
+
| **怎么开启** | 快速开始第 1 步 | 设置窗口、发给 AI 或终端 | 电脑上跟着装好 |
|
|
116
116
|
|
|
117
117
|
### 1. 学校订阅下载(CARSI)
|
|
118
118
|
|
|
119
119
|
开放渠道下不到的论文,可以借你学校的订阅来下。CARSI 是中国高校身份联盟,国内高校基本都已加入,用学校账号就能登录各家出版社。
|
|
120
120
|
|
|
121
|
-
安装:
|
|
122
|
-
|
|
123
|
-
```bash
|
|
124
|
-
paper-search carsi install # 安装时选择你的学校
|
|
125
|
-
paper-search carsi status --format text # 查看是否装好
|
|
126
|
-
```
|
|
127
|
-
|
|
128
|
-
<table>
|
|
129
|
-
<tr>
|
|
130
|
-
<td width="50%" valign="top">
|
|
131
|
-
<img src="assets/carsi-capsule.webp" alt="进度胶囊:下载时缩成小胶囊,悬停查看每篇进度,最小化到程序坞照常下载,点一下就回来">
|
|
132
|
-
<p><b>进度胶囊</b></p>
|
|
133
|
-
</td>
|
|
134
|
-
<td width="50%" valign="top">
|
|
135
|
-
<img src="assets/carsi-signin.webp" alt="自动登录学校:点胶囊里的题名,浏览器回到前台;自动点机构登录、填好学校,转到学校登录页">
|
|
136
|
-
<p><b>自动登录学校</b></p>
|
|
137
|
-
</td>
|
|
138
|
-
</tr>
|
|
139
|
-
<tr>
|
|
140
|
-
<td width="50%" valign="top">
|
|
141
|
-
<img src="assets/carsi-attention.webp" alt="需要你时提醒:要登录学校时胶囊变黄,点它切到浏览器,也能跳过这一篇">
|
|
142
|
-
<p><b>需要你时提醒</b></p>
|
|
143
|
-
</td>
|
|
144
|
-
<td width="50%" valign="top">
|
|
145
|
-
<img src="assets/carsi-finish.webp" alt="结束清单:跳过不想等的论文;下完列出结果,没下到的写明原因,点题名在自己的浏览器里打开">
|
|
146
|
-
<p><b>结束清单</b></p>
|
|
147
|
-
</td>
|
|
148
|
-
</tr>
|
|
149
|
-
</table>
|
|
150
|
-
|
|
151
121
|
- **学校账号就能用**:不用另外申请 key;出版社 API key 只覆盖 Elsevier、Springer 两家。
|
|
152
122
|
- **深度适配出版社**:深度优化了下载的通用流程,并且针对 30 多家出版社逐家写了专门规则,机构登录入口在哪、PDF 和补充材料怎么取,都按各自出版社的实际情况来,下载更准、更少漏篇。优化的出版社主要有:
|
|
153
123
|
- 综合:Elsevier(含 Cell、Lancet)、Springer Nature(含 Nature、BMC)、Wiley、Oxford Academic、Taylor & Francis、Sage、PNAS、Science
|
|
@@ -158,6 +128,33 @@ paper-search carsi status --format text # 查看是否装好
|
|
|
158
128
|
- **验证框自动点击**:遇到人机验证,程序自动定位并点击,网站放行后继续下载;过不去才提醒你。
|
|
159
129
|
- **后台下载不打扰**:浏览器在后台工作。屏幕角落的进度胶囊显示进度;需要你登录学校或手动验证时变成琥珀色,点一下就切到浏览器,处理完程序接着下载。
|
|
160
130
|
|
|
131
|
+
安装:
|
|
132
|
+
|
|
133
|
+
```bash
|
|
134
|
+
paper-search carsi install # 安装时选择你的学校
|
|
135
|
+
paper-search carsi status --format text # 查看是否装好
|
|
136
|
+
```
|
|
137
|
+
|
|
138
|
+
**进度胶囊**
|
|
139
|
+
|
|
140
|
+
<p align="center"><img src="assets/carsi-capsule.webp" width="840" alt="进度胶囊:下载时缩成小胶囊,悬停查看每篇进度,最小化到程序坞照常下载,点一下就回来"></p>
|
|
141
|
+
|
|
142
|
+
**自动过验证**
|
|
143
|
+
|
|
144
|
+
<p align="center"><img src="assets/carsi-verify.webp" width="840" alt="自动过验证:被人机验证页拦住时,验证自动通过,不用你动手"></p>
|
|
145
|
+
|
|
146
|
+
**自动登录学校**
|
|
147
|
+
|
|
148
|
+
<p align="center"><img src="assets/carsi-signin.webp" width="840" alt="自动登录学校:点胶囊里的题名,浏览器回到前台;自动点机构登录、填好学校,转到学校登录页"></p>
|
|
149
|
+
|
|
150
|
+
**需要你时提醒**
|
|
151
|
+
|
|
152
|
+
<p align="center"><img src="assets/carsi-attention.webp" width="840" alt="需要你时提醒:要登录学校时胶囊变黄,点它切到浏览器,也能跳过这一篇"></p>
|
|
153
|
+
|
|
154
|
+
**结束清单**
|
|
155
|
+
|
|
156
|
+
<p align="center"><img src="assets/carsi-finish.webp" width="840" alt="结束清单:跳过不想等的论文;下完列出结果,没下到的写明原因,点题名在自己的浏览器里打开"></p>
|
|
157
|
+
|
|
161
158
|
### 2. API key
|
|
162
159
|
|
|
163
160
|
按用途分四类,需要哪类就申请对应的 key,再用[快速开始第 3 步](#3-按需填-api-key)里的任一方式填入。
|
|
@@ -194,16 +191,6 @@ paper-search carsi status --format text # 查看是否装好
|
|
|
194
191
|
| OpenAIRE | `OPENAIRE_API_KEY` | [OpenAIRE](https://develop.openaire.eu/) |
|
|
195
192
|
| OpenAlex(被引超过 1 万篇时列全) | `OPENALEX_API_KEY` | [OpenAlex](https://openalex.org/settings/api) |
|
|
196
193
|
|
|
197
|
-
常用命令:
|
|
198
|
-
|
|
199
|
-
```bash
|
|
200
|
-
paper-search setup # 逐项填写常用的几项
|
|
201
|
-
paper-search setup EASYSCHOLAR_KEY # 只填某一项
|
|
202
|
-
paper-search settings # 装了学校订阅下载时:在设置窗口里填
|
|
203
|
-
paper-search config list --pretty # 查看已配置的项,key 脱敏显示
|
|
204
|
-
paper-search config test --format text # 测试已填的 key 能不能用
|
|
205
|
-
```
|
|
206
|
-
|
|
207
194
|
配置保存在 `~/.config/paper-search-cli/config.json`,只有你自己能读。下载文件夹、联系邮箱、代理和自动更新等其他设置,见 [使用说明 · 其他设置](docs/guide.zh.md#其他设置)。
|
|
208
195
|
|
|
209
196
|
## 更多文档
|
|
@@ -20,7 +20,7 @@
|
|
|
20
20
|
"name": "Semantic Scholar",
|
|
21
21
|
"use": "搜正文片段",
|
|
22
22
|
"url": "https://www.semanticscholar.org/product/api",
|
|
23
|
-
"guide": "https://
|
|
23
|
+
"guide": "https://docs.qq.com/aio/DTW9RdFVHc2hJUmpx",
|
|
24
24
|
"guide_label": "申请教程",
|
|
25
25
|
"keys": [
|
|
26
26
|
{
|
|
@@ -130,6 +130,10 @@
|
|
|
130
130
|
"已检查,页面未列出补充材料": "Checked; no supp. listed",
|
|
131
131
|
"批量下载已停止,结果未确认": "Batch stopped; result unconfirmed",
|
|
132
132
|
"机构 PDF 下载": "School PDF download",
|
|
133
|
+
"学校登录": "School sign-in",
|
|
134
|
+
"打开文章页": "Opening the article",
|
|
135
|
+
"已登录学校": "Signed in",
|
|
136
|
+
"没有完成登录": "Not signed in",
|
|
133
137
|
"机构 PDF 批量下载": "School PDF batch",
|
|
134
138
|
"等待下载进程响应(暂无新进度)": "Waiting for the download (no news)",
|
|
135
139
|
"DOI 没指向能登录的网站": "DOI leads to no login site",
|
|
@@ -167,6 +171,7 @@
|
|
|
167
171
|
"登录后没回到出版社": "No return to publisher",
|
|
168
172
|
"登录重试已用尽": "Login retries used up",
|
|
169
173
|
"登录页被关闭": "Login page closed",
|
|
174
|
+
"下载浏览器被关闭了": "Browser closed",
|
|
170
175
|
"等学校登录超时": "School login timed out",
|
|
171
176
|
"网站人机验证拦截": "Blocked by bot check",
|
|
172
177
|
"网站拦截了当前网络": "Site blocked network",
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
"""
|
|
1
|
+
"""Publisher cookies the download browser saved: kept, merged and restored.
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
3
|
+
Signing in is the download's own work (``login`` runs its steps without the
|
|
4
|
+
PDF); the old window that only captured cookies was removed on 2026-11-09.
|
|
5
5
|
"""
|
|
6
6
|
|
|
7
7
|
from __future__ import annotations
|
|
@@ -43,26 +43,6 @@ PUBLISHER_DOMAINS = [
|
|
|
43
43
|
"frontiersin.org",
|
|
44
44
|
]
|
|
45
45
|
|
|
46
|
-
# Publisher login URLs for quick access
|
|
47
|
-
PUBLISHER_LOGIN_URLS = {
|
|
48
|
-
"elsevier": "https://www.sciencedirect.com/",
|
|
49
|
-
"springer": "https://link.springer.com/",
|
|
50
|
-
"wiley": "https://onlinelibrary.wiley.com/",
|
|
51
|
-
"nature": "https://www.nature.com/",
|
|
52
|
-
"science": "https://www.science.org/",
|
|
53
|
-
"ieee": "https://ieeexplore.ieee.org/",
|
|
54
|
-
"tandfonline": "https://www.tandfonline.com/",
|
|
55
|
-
"pnas": "https://www.pnas.org/",
|
|
56
|
-
"acs": "https://pubs.acs.org/",
|
|
57
|
-
"rsc": "https://pubs.rsc.org/",
|
|
58
|
-
"aip": "https://pubs.aip.org/",
|
|
59
|
-
"aps": "https://journals.aps.org/",
|
|
60
|
-
"iop": "https://iopscience.iop.org/",
|
|
61
|
-
"oxford": "https://academic.oup.com/",
|
|
62
|
-
"acm": "https://dl.acm.org/",
|
|
63
|
-
"sage-cn": "https://sage.cnpereading.com/login",
|
|
64
|
-
}
|
|
65
|
-
|
|
66
46
|
# Cloudflare bot-management cookies: they carry no login.
|
|
67
47
|
_CLOUDFLARE_COOKIE_NAMES = {"__cf_bm", "_cfuvid", "cf_clearance", "cf_chl_rc_ni"}
|
|
68
48
|
|
|
@@ -97,127 +77,6 @@ def _is_publisher_cookie(cookie: dict[str, Any]) -> bool:
|
|
|
97
77
|
return any(domain == d or domain.endswith("." + d) for d in PUBLISHER_DOMAINS)
|
|
98
78
|
|
|
99
79
|
|
|
100
|
-
def extract_via_browser(
|
|
101
|
-
config: dict[str, Any],
|
|
102
|
-
*,
|
|
103
|
-
url: str = "https://www.sciencedirect.com/",
|
|
104
|
-
max_wait: int = 300,
|
|
105
|
-
) -> dict[str, Any]:
|
|
106
|
-
"""Open visible browser for institutional login, then capture publisher cookies.
|
|
107
|
-
|
|
108
|
-
Args:
|
|
109
|
-
config: backend config dict.
|
|
110
|
-
url: URL to open (default: ScienceDirect).
|
|
111
|
-
max_wait: Max seconds to wait for login.
|
|
112
|
-
|
|
113
|
-
Returns:
|
|
114
|
-
Result dict with success, cookies_count, domains, etc.
|
|
115
|
-
"""
|
|
116
|
-
try:
|
|
117
|
-
from .backend import CHROME_MISSING, launch
|
|
118
|
-
from .backend import is_available as _browser_backend_available
|
|
119
|
-
if not _browser_backend_available(config=config):
|
|
120
|
-
return {
|
|
121
|
-
"success": False,
|
|
122
|
-
"error": "no browser backend available",
|
|
123
|
-
"fix": CHROME_MISSING,
|
|
124
|
-
}
|
|
125
|
-
except ImportError:
|
|
126
|
-
return {
|
|
127
|
-
"success": False,
|
|
128
|
-
"error": "no browser backend available",
|
|
129
|
-
"fix": "paper-search carsi update",
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
from ..config import DATA_DIR
|
|
133
|
-
cache_dir = Path(config.get("cache_dir", str(DATA_DIR / "cache")))
|
|
134
|
-
cookie_file = cache_dir / "publisher_cookies.json"
|
|
135
|
-
netscape_file = cache_dir / "publisher_cookies.txt"
|
|
136
|
-
|
|
137
|
-
log.info(f" [cookies] Opening browser: {url}")
|
|
138
|
-
print(f"\n 请在浏览器中登录你的机构账号(如学校图书馆)")
|
|
139
|
-
print(f" 打开页面: {url}")
|
|
140
|
-
print(f" 登录完成后关闭浏览器窗口即可\n")
|
|
141
|
-
|
|
142
|
-
try:
|
|
143
|
-
browser = launch(headless=False, humanize=True)
|
|
144
|
-
context = browser.new_context(viewport={"width": 1440, "height": 900})
|
|
145
|
-
page = context.new_page()
|
|
146
|
-
|
|
147
|
-
try:
|
|
148
|
-
page.goto(url, wait_until="domcontentloaded", timeout=60000)
|
|
149
|
-
except Exception as exc:
|
|
150
|
-
log.info(f" [cookies] Page load warning: {exc}")
|
|
151
|
-
|
|
152
|
-
# Auto-dismiss cookie consent popups (common on Elsevier/Cell/Wiley/etc.)
|
|
153
|
-
time.sleep(2)
|
|
154
|
-
for js in [
|
|
155
|
-
# Elsevier/Cell cookie banner
|
|
156
|
-
"document.querySelector('#onetrust-accept-btn-handler')?.click()",
|
|
157
|
-
# OneTrust general
|
|
158
|
-
"document.querySelector('.onetrust-close-btn-handler')?.click()",
|
|
159
|
-
# Generic consent banners
|
|
160
|
-
"document.querySelector('[class*=\"cookie-accept\"], [class*=\"consent-accept\"]')?.click()",
|
|
161
|
-
"document.querySelector('button[id*=\"accept\"], button[class*=\"accept\"]')?.click()",
|
|
162
|
-
]:
|
|
163
|
-
try:
|
|
164
|
-
page.evaluate(js)
|
|
165
|
-
except Exception:
|
|
166
|
-
pass
|
|
167
|
-
|
|
168
|
-
# Wait for user to close browser
|
|
169
|
-
try:
|
|
170
|
-
page.wait_for_event("close", timeout=max_wait * 1000)
|
|
171
|
-
except Exception:
|
|
172
|
-
pass
|
|
173
|
-
|
|
174
|
-
# Capture all cookies
|
|
175
|
-
all_cookies = context.cookies()
|
|
176
|
-
|
|
177
|
-
if not all_cookies:
|
|
178
|
-
browser.close()
|
|
179
|
-
return {
|
|
180
|
-
"success": False,
|
|
181
|
-
"message": "未捕获到 cookies。请确保已登录机构账号。",
|
|
182
|
-
}
|
|
183
|
-
|
|
184
|
-
# Filter publisher cookies + keep all for completeness
|
|
185
|
-
publisher_cookies = [c for c in all_cookies if _is_publisher_cookie(c)]
|
|
186
|
-
save_cookies = publisher_cookies if publisher_cookies else all_cookies
|
|
187
|
-
|
|
188
|
-
# Save
|
|
189
|
-
_save_cookies_json(save_cookies, cookie_file)
|
|
190
|
-
_save_cookies_netscape(save_cookies, netscape_file)
|
|
191
|
-
|
|
192
|
-
# Import into the shared browser if available
|
|
193
|
-
browser_imported = 0
|
|
194
|
-
try:
|
|
195
|
-
from .engine import import_cookies, is_available
|
|
196
|
-
if is_available(config):
|
|
197
|
-
browser_imported = import_cookies(netscape_file, config)
|
|
198
|
-
except Exception:
|
|
199
|
-
pass
|
|
200
|
-
|
|
201
|
-
browser.close()
|
|
202
|
-
|
|
203
|
-
domains_found = list({c.get("domain", "").lstrip(".") for c in save_cookies})[:10]
|
|
204
|
-
return {
|
|
205
|
-
"success": True,
|
|
206
|
-
"cookies_count": len(save_cookies),
|
|
207
|
-
"total_captured": len(all_cookies),
|
|
208
|
-
"cookie_file": str(cookie_file),
|
|
209
|
-
"netscape_file": str(netscape_file),
|
|
210
|
-
"domains": domains_found,
|
|
211
|
-
"browser_imported": browser_imported,
|
|
212
|
-
"message": f"捕获 {len(all_cookies)} 个 cookies,其中 {len(publisher_cookies)} 个属于出版社。"
|
|
213
|
-
f"已保存,后续下载自动使用。",
|
|
214
|
-
}
|
|
215
|
-
|
|
216
|
-
except Exception as exc:
|
|
217
|
-
log.info(f" [cookies] Error: {exc}")
|
|
218
|
-
return {"success": False, "error": str(exc)}
|
|
219
|
-
|
|
220
|
-
|
|
221
80
|
def load_saved_cookies(config: dict[str, Any]) -> list[dict[str, Any]]:
|
|
222
81
|
"""Load previously saved publisher cookies, filtering out expired ones."""
|
|
223
82
|
from ..config import DATA_DIR
|
|
@@ -322,65 +181,3 @@ def merge_cookies(new_cookies: list[dict[str, Any]], config: dict[str, Any], *,
|
|
|
322
181
|
_save_cookies_netscape(result, netscape_file)
|
|
323
182
|
|
|
324
183
|
return result
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
def _is_doi(text: str) -> bool:
|
|
328
|
-
return text.startswith("10.") and "/" in text
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
def publisher_login(
|
|
332
|
-
identifier: str,
|
|
333
|
-
config: dict[str, Any],
|
|
334
|
-
*,
|
|
335
|
-
max_wait: int = 300,
|
|
336
|
-
) -> dict[str, Any]:
|
|
337
|
-
"""Open browser for institutional login on a publisher article page.
|
|
338
|
-
|
|
339
|
-
Takes a DOI or publisher name, resolves to the article page, and opens
|
|
340
|
-
a visible stealth browser. User clicks "Access through your institution",
|
|
341
|
-
completes SSO login, then closes the browser. Cookies are captured and
|
|
342
|
-
imported into the download browser for automated downloads.
|
|
343
|
-
|
|
344
|
-
Args:
|
|
345
|
-
identifier: DOI (e.g. 10.1126/science.aec6396) or publisher name
|
|
346
|
-
(e.g. "elsevier", "wiley", "nature", "springer", "ieee",
|
|
347
|
-
"science", "tandfonline", "pnas", "acs", "rsc", "aip",
|
|
348
|
-
"aps", "iop", "oxford", "acm")
|
|
349
|
-
config: backend config dict
|
|
350
|
-
max_wait: Max seconds to wait for login (default 300)
|
|
351
|
-
|
|
352
|
-
Returns:
|
|
353
|
-
Result dict with success, cookies_count, domains, message.
|
|
354
|
-
"""
|
|
355
|
-
import re
|
|
356
|
-
|
|
357
|
-
# Resolve identifier to a URL
|
|
358
|
-
if _is_doi(identifier):
|
|
359
|
-
# DOI → resolve to article URL
|
|
360
|
-
url = f"https://doi.org/{identifier}"
|
|
361
|
-
log.info(f" [login] DOI detected, opening article: {url}")
|
|
362
|
-
elif identifier.lower() in PUBLISHER_LOGIN_URLS:
|
|
363
|
-
url = PUBLISHER_LOGIN_URLS[identifier.lower()]
|
|
364
|
-
log.info(f" [login] Publisher '{identifier}', opening: {url}")
|
|
365
|
-
elif re.match(r"https?://", identifier):
|
|
366
|
-
url = identifier
|
|
367
|
-
log.info(f" [login] URL detected: {url}")
|
|
368
|
-
else:
|
|
369
|
-
# Try fuzzy publisher name match
|
|
370
|
-
lower = identifier.lower()
|
|
371
|
-
match = None
|
|
372
|
-
for key in PUBLISHER_LOGIN_URLS:
|
|
373
|
-
if key in lower or lower in key:
|
|
374
|
-
match = key
|
|
375
|
-
break
|
|
376
|
-
if match:
|
|
377
|
-
url = PUBLISHER_LOGIN_URLS[match]
|
|
378
|
-
log.info(f" [login] Matched publisher '{match}', opening: {url}")
|
|
379
|
-
else:
|
|
380
|
-
available = ", ".join(sorted(PUBLISHER_LOGIN_URLS.keys()))
|
|
381
|
-
return {
|
|
382
|
-
"success": False,
|
|
383
|
-
"error": f"Unknown publisher: '{identifier}'. Available: {available}",
|
|
384
|
-
}
|
|
385
|
-
|
|
386
|
-
return extract_via_browser(config, url=url, max_wait=max_wait)
|