v1.0.6: 导入网址文件增加追加/覆盖处理方式选择(默认追加)
This commit is contained in:
@@ -33,7 +33,10 @@
|
|||||||
- 运行中的任务参数支持**热更新**(修改后从下一页起生效)
|
- 运行中的任务参数支持**热更新**(修改后从下一页起生效)
|
||||||
|
|
||||||
### 2. 批量爬取模式
|
### 2. 批量爬取模式
|
||||||
一次粘贴多个网址(每行一个,`#` 注释),或点击「📂 导入网址文件」上传 .txt 文件批量导入(自动识别 UTF-8/GBK 编码、自动去重、自动清理行内注释):
|
一次粘贴多个网址(每行一个,`#` 注释),或点击「📂 导入网址文件」上传 .txt 文件批量导入:
|
||||||
|
- **处理方式可选**:追加(保留已有,默认)或覆盖(清空已有)
|
||||||
|
- 自动识别 UTF-8/GBK 编码、自动去重、自动清理行内注释
|
||||||
|
可配置:
|
||||||
- 项目名称、输出目录(默认 `out/<任务ID>`,可填绝对路径)
|
- 项目名称、输出目录(默认 `out/<任务ID>`,可填绝对路径)
|
||||||
- 爬取间隔(随机秒数区间,防封 IP)、单页超时
|
- 爬取间隔(随机秒数区间,防封 IP)、单页超时
|
||||||
- 失败重试次数 / 重试间隔
|
- 失败重试次数 / 重试间隔
|
||||||
|
|||||||
+11
-4
@@ -174,10 +174,12 @@ async function readFileSmart(file) {
|
|||||||
return text;
|
return text;
|
||||||
}
|
}
|
||||||
|
|
||||||
function importUrlsText(text) {
|
function importUrlsText(text, mode) {
|
||||||
const ta = $("taskForm").elements["urls"];
|
const ta = $("taskForm").elements["urls"];
|
||||||
const clean = (s) => s.split(" #")[0].trim(); // 去掉行内注释 (URL 不含空格, 安全)
|
const clean = (s) => s.split(" #")[0].trim(); // 去掉行内注释 (URL 不含空格, 安全)
|
||||||
const existing = new Set(ta.value.split(/\r?\n/).map(clean).filter(Boolean));
|
const existing = new Set(
|
||||||
|
mode === "overwrite" ? [] : ta.value.split(/\r?\n/).map(clean).filter(Boolean)
|
||||||
|
);
|
||||||
const fresh = text.split(/\r?\n/).map(clean).filter(Boolean);
|
const fresh = text.split(/\r?\n/).map(clean).filter(Boolean);
|
||||||
let added = 0;
|
let added = 0;
|
||||||
for (const line of fresh) {
|
for (const line of fresh) {
|
||||||
@@ -198,9 +200,14 @@ $("urlFileInput").onchange = async (e) => {
|
|||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
const text = await readFileSmart(file);
|
const text = await readFileSmart(file);
|
||||||
const r = importUrlsText(text);
|
const mode = $("importMode").value;
|
||||||
|
const r = importUrlsText(text, mode);
|
||||||
formDirty = true;
|
formDirty = true;
|
||||||
toast(`已导入 ${file.name}:共 ${r.total} 行,新增 ${r.added} 条网址`);
|
if (mode === "overwrite") {
|
||||||
|
toast(`已导入 ${file.name}:共 ${r.total} 行(覆盖原列表,新增 ${r.added} 条)`);
|
||||||
|
} else {
|
||||||
|
toast(`已导入 ${file.name}:共 ${r.total} 行,新增 ${r.added} 条网址(追加)`);
|
||||||
|
}
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
toast("文件读取失败: " + err.message, true);
|
toast("文件读取失败: " + err.message, true);
|
||||||
}
|
}
|
||||||
|
|||||||
+5
-1
@@ -77,7 +77,11 @@
|
|||||||
<label>网址列表(每行一个,# 开头为注释)</label>
|
<label>网址列表(每行一个,# 开头为注释)</label>
|
||||||
<div class="row2" style="align-items:center">
|
<div class="row2" style="align-items:center">
|
||||||
<button type="button" class="btn sm" id="btnImportUrls">📂 导入网址文件(.txt)</button>
|
<button type="button" class="btn sm" id="btnImportUrls">📂 导入网址文件(.txt)</button>
|
||||||
<span class="card-line">支持 UTF-8 / GBK 编码,自动去重追加</span>
|
<select id="importMode" title="对已有网址的处理方式">
|
||||||
|
<option value="append" selected>追加(保留已有)</option>
|
||||||
|
<option value="overwrite">覆盖(清空已有)</option>
|
||||||
|
</select>
|
||||||
|
<span class="card-line">支持 UTF-8 / GBK,自动去重</span>
|
||||||
<input type="file" id="urlFileInput" accept=".txt,.csv,.urls,text/plain" hidden>
|
<input type="file" id="urlFileInput" accept=".txt,.csv,.urls,text/plain" hidden>
|
||||||
</div>
|
</div>
|
||||||
<textarea name="urls" rows="5" placeholder="https://www.example.com/ https://www.example.com/page2"></textarea>
|
<textarea name="urls" rows="5" placeholder="https://www.example.com/ https://www.example.com/page2"></textarea>
|
||||||
|
|||||||
Reference in New Issue
Block a user