Excel 文件移除 href 和 detail_content 字段

修复账号解析逻辑,正确提取昵称和账号
优化 Web 性能
This commit is contained in:
mzl
2026-01-09 17:28:03 +08:00
parent 6deca7ac72
commit e6845620cc
2 changed files with 38 additions and 8 deletions
+14 -4
View File
@@ -881,12 +881,17 @@
}
}
let _lastProg = '';
let _lastUpdateTime = 0;
function updateProgressLine(s){
if(!s || !s.progress) return;
const p = s.progress;
const key = `${p.status}-${p.done}-${p.total}-${p.current}`;
if(key === _lastProg) return;
// 限制更新频率:最多每 2 秒更新一次进度
const now = Date.now();
if(now - _lastUpdateTime < 2000 && key === _lastProg) return;
_lastProg = key;
_lastUpdateTime = now;
if(p.status === 'running'){
log(`进度:${p.done}/${p.total} 当前:${p.current || '-'}`);
}else if(p.status && p.status !== 'idle'){
@@ -1367,13 +1372,18 @@
});
// ========= 文件输出 =========
let _refreshFilesPending = false;
async function refreshOutFiles(){
if(!authed) return;
if(_refreshFilesPending) return; // 防止重复请求
_refreshFilesPending = true;
try{
const files = await apiGet('/api/files');
renderFiles(files || []);
}catch(e){
// ignore
}finally{
_refreshFilesPending = false;
}
}
@@ -1477,10 +1487,10 @@
log('页面加载完成。');
connectLogs();
await pollStatus();
// 每2秒无感检测一次(不刷新页面)
setInterval(pollStatus, 5000);
// 输出文件偶尔刷新一下
setInterval(refreshOutFiles, 15000);
// 状态轮询:降低频率到 10 秒(原 5 秒)
setInterval(pollStatus, 10000);
// 输出文件偶尔刷新一下:降低频率到 30 秒(原 15 秒)
setInterval(refreshOutFiles, 30000);
})();
</script>
+24 -4
View File
@@ -558,11 +558,31 @@ def resolve_profile_by_search(
if use_anchor_only:
href = (it.get_attribute("href") or "").strip()
nickname = ""
xhs_no = ""
try:
nickname = (it.inner_text() or "").strip()
full_text = (it.inner_text() or "").strip()
# 解析昵称和账号:从完整文本中提取
# 示例:青岛西门子家电规划师-海燕呀 1天前更新 小红书号:V13863940939 粉丝・52 笔记・217 关注
# 提取昵称:从开头到 "小红书号" 之前,去除时间信息
lines = full_text.split('\n')
main_text = lines[0] if lines else full_text
# 提取小红书号
m = re.search(r'小红书号[::]\s*([A-Za-z0-9]+)', main_text)
if m:
xhs_no = m.group(1).strip()
# 提取昵称:去除时间信息和账号信息
# 先移除小红书号部分
nickname_part = re.sub(r'小红书号[::]\s*[A-Za-z0-9]+.*', '', main_text)
# 移除时间信息(如 "1天前更新")
nickname_part = re.sub(r'\d+[天小时分秒]*前更新', '', nickname_part)
# 移除粉丝、笔记、关注信息
nickname_part = re.sub(r'粉丝[・・]\d+\s*笔记[・・]\d+\s*关注.*', '', nickname_part)
nickname = nickname_part.strip()
except Exception:
nickname = ""
xhs_no = ""
xhs_no = ""
else:
href = (it.locator("a[href^='/user/profile/']").first.get_attribute("href") or "").strip()
nickname = ""
@@ -947,8 +967,8 @@ def crawl_detail(
wb = Workbook()
ws = wb.active
ws.title = "data"
# 按需求文档的字段顺序
headers = ["href", "detail_title", "detail_content", "like", "collect", "comment", "detail_date_loc", "crawled_at"]
# Excel 导出字段(不包含 href 和 detail_content)
headers = ["detail_title", "like", "collect", "comment", "detail_date_loc", "crawled_at"]
ws.append(headers)
for r in results:
ws.append([r.get(h, "") for h in headers])