UNPKG

zhilian-auto-hi

Version:

智联招聘自动打招呼工具 - 自动化招聘流程的命令行工具

67 lines (66 loc) 2.32 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.extractLocation = extractLocation; exports.checkLocationMatch = checkLocationMatch; /** * 地址相关工具函数 */ /** * 从简历元信息中提取现居地址 * @param page Playwright页面对象 * @returns 提取到的现居地址,如果未找到则返回null */ async function extractLocation(page) { try { // 使用 Playwright 的 getByText 方法配合正则表达式查找现居地址 // 匹配格式:现居xxx(xxx为地址信息) const metaContainer = page.locator('.resume-basic-new__meta'); const locationElement = metaContainer.locator('.resume-basic-new__meta-item').getByText(/现居.+/); const elementCount = await locationElement.count(); if (elementCount === 0) { return null; } // 获取第一个匹配元素的文本内容 const locationText = await locationElement.first().textContent(); if (locationText) { // 提取现居地址信息,去掉"现居"前缀 const locationMatch = locationText.match(/现居(.+)/); if (locationMatch && locationMatch[1]) { return locationMatch[1].trim(); } } return null; } catch (error) { console.error('提取现居地址时出错:', error); return null; } } /** * 检查现居地址是否符合筛选条件 * @param extractedLocation 提取到的现居地址 * @param locationFilter 地址筛选条件数组 * @returns 匹配结果 */ function checkLocationMatch(extractedLocation, locationFilter) { // 如果没有配置地址筛选条件,则通过筛选 if (!locationFilter || locationFilter.length === 0) { return { isMatch: true, extractedLocation: extractedLocation || '' }; } // 如果没有提取到地址信息,则不通过筛选 if (!extractedLocation) { return { isMatch: false, extractedLocation: '' }; } // 检查提取到的地址是否包含筛选条件中的任一地址 const isMatch = locationFilter.some(location => extractedLocation.includes(location)); return { isMatch, extractedLocation }; }