Excel 文件移除 href 和 detail_content 字段
修复账号解析逻辑,正确提取昵称和账号 优化 Web 性能
This commit is contained in:
+14
-4
@@ -881,12 +881,17 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
let _lastProg = '';
|
let _lastProg = '';
|
||||||
|
let _lastUpdateTime = 0;
|
||||||
function updateProgressLine(s){
|
function updateProgressLine(s){
|
||||||
if(!s || !s.progress) return;
|
if(!s || !s.progress) return;
|
||||||
const p = s.progress;
|
const p = s.progress;
|
||||||
const key = `${p.status}-${p.done}-${p.total}-${p.current}`;
|
const key = `${p.status}-${p.done}-${p.total}-${p.current}`;
|
||||||
if(key === _lastProg) return;
|
if(key === _lastProg) return;
|
||||||
|
// 限制更新频率:最多每 2 秒更新一次进度
|
||||||
|
const now = Date.now();
|
||||||
|
if(now - _lastUpdateTime < 2000 && key === _lastProg) return;
|
||||||
_lastProg = key;
|
_lastProg = key;
|
||||||
|
_lastUpdateTime = now;
|
||||||
if(p.status === 'running'){
|
if(p.status === 'running'){
|
||||||
log(`进度:${p.done}/${p.total} 当前:${p.current || '-'}`);
|
log(`进度:${p.done}/${p.total} 当前:${p.current || '-'}`);
|
||||||
}else if(p.status && p.status !== 'idle'){
|
}else if(p.status && p.status !== 'idle'){
|
||||||
@@ -1367,13 +1372,18 @@
|
|||||||
});
|
});
|
||||||
|
|
||||||
// ========= 文件输出 =========
|
// ========= 文件输出 =========
|
||||||
|
let _refreshFilesPending = false;
|
||||||
async function refreshOutFiles(){
|
async function refreshOutFiles(){
|
||||||
if(!authed) return;
|
if(!authed) return;
|
||||||
|
if(_refreshFilesPending) return; // 防止重复请求
|
||||||
|
_refreshFilesPending = true;
|
||||||
try{
|
try{
|
||||||
const files = await apiGet('/api/files');
|
const files = await apiGet('/api/files');
|
||||||
renderFiles(files || []);
|
renderFiles(files || []);
|
||||||
}catch(e){
|
}catch(e){
|
||||||
// ignore
|
// ignore
|
||||||
|
}finally{
|
||||||
|
_refreshFilesPending = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1477,10 +1487,10 @@
|
|||||||
log('页面加载完成。');
|
log('页面加载完成。');
|
||||||
connectLogs();
|
connectLogs();
|
||||||
await pollStatus();
|
await pollStatus();
|
||||||
// 每2秒无感检测一次(不刷新页面)
|
// 状态轮询:降低频率到 10 秒(原 5 秒)
|
||||||
setInterval(pollStatus, 5000);
|
setInterval(pollStatus, 10000);
|
||||||
// 输出文件偶尔刷新一下
|
// 输出文件偶尔刷新一下:降低频率到 30 秒(原 15 秒)
|
||||||
setInterval(refreshOutFiles, 15000);
|
setInterval(refreshOutFiles, 30000);
|
||||||
})();
|
})();
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
|||||||
+24
-4
@@ -558,11 +558,31 @@ def resolve_profile_by_search(
|
|||||||
if use_anchor_only:
|
if use_anchor_only:
|
||||||
href = (it.get_attribute("href") or "").strip()
|
href = (it.get_attribute("href") or "").strip()
|
||||||
nickname = ""
|
nickname = ""
|
||||||
|
xhs_no = ""
|
||||||
try:
|
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:
|
except Exception:
|
||||||
nickname = ""
|
nickname = ""
|
||||||
xhs_no = ""
|
xhs_no = ""
|
||||||
else:
|
else:
|
||||||
href = (it.locator("a[href^='/user/profile/']").first.get_attribute("href") or "").strip()
|
href = (it.locator("a[href^='/user/profile/']").first.get_attribute("href") or "").strip()
|
||||||
nickname = ""
|
nickname = ""
|
||||||
@@ -947,8 +967,8 @@ def crawl_detail(
|
|||||||
wb = Workbook()
|
wb = Workbook()
|
||||||
ws = wb.active
|
ws = wb.active
|
||||||
ws.title = "data"
|
ws.title = "data"
|
||||||
# 按需求文档的字段顺序
|
# Excel 导出字段(不包含 href 和 detail_content)
|
||||||
headers = ["href", "detail_title", "detail_content", "like", "collect", "comment", "detail_date_loc", "crawled_at"]
|
headers = ["detail_title", "like", "collect", "comment", "detail_date_loc", "crawled_at"]
|
||||||
ws.append(headers)
|
ws.append(headers)
|
||||||
for r in results:
|
for r in results:
|
||||||
ws.append([r.get(h, "") for h in headers])
|
ws.append([r.get(h, "") for h in headers])
|
||||||
|
|||||||
Reference in New Issue
Block a user