自动获取真实姓名作为账号备注(静默完成)
This commit is contained in:
@@ -132,6 +132,37 @@ class APIBrowser:
|
|||||||
fields[name] = field.get('value', '')
|
fields[name] = field.get('value', '')
|
||||||
return fields
|
return fields
|
||||||
|
|
||||||
|
def get_real_name(self) -> Optional[str]:
|
||||||
|
"""
|
||||||
|
获取用户真实姓名
|
||||||
|
从 center.aspx 页面解析姓名信息
|
||||||
|
返回: 姓名字符串,失败返回 None
|
||||||
|
"""
|
||||||
|
if not self.logged_in:
|
||||||
|
return None
|
||||||
|
|
||||||
|
try:
|
||||||
|
url = f"{BASE_URL}/admin/center.aspx"
|
||||||
|
resp = self._request_with_retry('get', url)
|
||||||
|
soup = BeautifulSoup(resp.text, 'html.parser')
|
||||||
|
|
||||||
|
# 查找包含"姓名:"的元素
|
||||||
|
# 页面格式: <li><p>姓名:喻勇祥(19174616018) 人力资源编码: ...</p></li>
|
||||||
|
nlist = soup.find('div', {'class': 'nlist-5'})
|
||||||
|
if nlist:
|
||||||
|
first_li = nlist.find('li')
|
||||||
|
if first_li:
|
||||||
|
text = first_li.get_text()
|
||||||
|
# 解析姓名:格式为 "姓名:XXX(手机号)"
|
||||||
|
match = re.search(r'姓名[::]\s*([^\((]+)', text)
|
||||||
|
if match:
|
||||||
|
real_name = match.group(1).strip()
|
||||||
|
if real_name:
|
||||||
|
return real_name
|
||||||
|
return None
|
||||||
|
except Exception as e:
|
||||||
|
return None
|
||||||
|
|
||||||
def login(self, username: str, password: str) -> bool:
|
def login(self, username: str, password: str) -> bool:
|
||||||
"""登录"""
|
"""登录"""
|
||||||
self.log(f"[API] 登录: {username}")
|
self.log(f"[API] 登录: {username}")
|
||||||
|
|||||||
11
app.py
11
app.py
@@ -2110,6 +2110,17 @@ def run_task(user_id, account_id, browse_type, enable_screenshot=True, source="m
|
|||||||
api_browser.save_cookies_for_playwright(account.username)
|
api_browser.save_cookies_for_playwright(account.username)
|
||||||
database.reset_account_login_status(account_id)
|
database.reset_account_login_status(account_id)
|
||||||
|
|
||||||
|
# 如果账号没有备注,自动获取真实姓名作为备注
|
||||||
|
if not account.remark:
|
||||||
|
try:
|
||||||
|
real_name = api_browser.get_real_name()
|
||||||
|
if real_name:
|
||||||
|
account.remark = real_name
|
||||||
|
database.update_account_remark(account_id, real_name)
|
||||||
|
socketio.emit('account_update', account.to_dict(), room=f'user_{user_id}')
|
||||||
|
except Exception:
|
||||||
|
pass # 静默失败,不影响任务执行
|
||||||
|
|
||||||
if account_id in task_status:
|
if account_id in task_status:
|
||||||
task_status[account_id]["detail_status"] = "正在浏览"
|
task_status[account_id]["detail_status"] = "正在浏览"
|
||||||
log_to_client(f"开始浏览 '{browse_type}' 内容...", user_id, account_id)
|
log_to_client(f"开始浏览 '{browse_type}' 内容...", user_id, account_id)
|
||||||
|
|||||||
Reference in New Issue
Block a user