LinkedIn 个人资料抓取 + LLM 简历结构化提取工具
Project description
linkedin-lion
LinkedIn Talent 个人资料抓取 + LLM 简历结构化提取工具
基于 Typer + Rich 构建的现代 Python CLI 工具包,将 LinkedIn Talent 个人资料抓取与 LLM 简历信息提取整合为一套完整流程。
功能特性
lion scrape— 抓取单个 LinkedIn Talent Profile,提取纯文本保存为.txtlion batch— 从 URL 列表文件批量抓取,支持断点续传(已存在文件自动跳过)lion extract— 调用 LLM(llmdog)将.txt简历结构化为 JSON,支持批量处理- 全部命令通过 Rich 渲染输出,配色现代、信息层级清晰
- 核心函数均可作为 Python 模块导入使用
安装和环境配置
1. 安装包
pip install linkedin-lion
2. 配置 .env 文件
在项目根目录(或 ~/.linkedin_lion/)创建 .env 文件。
版本 A:最简配置(全依赖 llmdog 内置默认值)
# 仅配置 Selenium Cookie (lion scrape / lion batch 必填)
LION_COOKIE_FILE=cookie.json
适用场景:llmdog 已通过自身配置(如
~/.llmdog/config.json)设置好 API Key 和模型,无需在 linkedin-lion 層重复配置。
版本 B:完整配置(显式指定所有 LLM 参数)
# LLM 配置(lion extract 命令可用,均为可选)
LION_API_KEY=sk-xxxxxxxxxxxxxxxxxxxxxxxxxxxx
LION_API_URL=https://api.deepseek.com/v1/chat/completions
LION_MODEL=deepseek-chat
LION_TIMEOUT=60
LION_VERIFY_SSL=true
# Selenium Cookie 文件路径(lion scrape / lion batch 命令使用)
LION_COOKIE_FILE=cookie.json
所有 LLM 参数均为可选:未设置的字段不会传递给 llmdog,由 llmdog 自行使用其内置默认值。
3. 准备 Cookie 文件
将 LinkedIn Talent 的登录态 Cookie 导出为 cookie.json,放置于项目根目录或通过 --cookie 参数指定路径。
使用示例
lion scrape — 抓取单个 Profile
# 基础用法
lion scrape "https://www.linkedin.com/talent/profile/ACoAAA..." --folder ./output
# 指定 Cookie 文件 + 无头模式
lion scrape "https://www.linkedin.com/talent/profile/ACoAAA..." \
--cookie path/to/cookie.json \
--folder ./resumes \
--headless
# 查看完整帮助
lion scrape --help
lion batch — 批量抓取
准备 urls.txt(每行一个 LinkedIn URL):
https://www.linkedin.com/in/johndoe/
https://www.linkedin.com/in/janedoe/
# 批量抓取全部
lion batch urls.txt --output-dir ./resumes
# 仅处理第 10~50 条
lion batch urls.txt --output-dir ./resumes --start 9 --end 50
# 使用 diskcache URN 缓存(加速 Talent Profile 直链构建)
lion batch urls.txt --output-dir ./resumes --cache-dir /path/to/cache_dir
# 无头模式
lion batch urls.txt --output-dir ./resumes --headless
lion extract — LLM 简历提取
# 处理单个文件
lion extract resume.txt --output ./json_output
# 批量处理目录下所有 .txt 文件
lion extract ./resumes --output ./json_output
# 自定义提示模板
lion extract ./resumes --output ./json_output --prompt-file my_prompt.txt
# 增加重试次数
lion extract ./resumes --output ./json_output --max-retries 5
完整工作流示例
# Step 1:批量抓取 LinkedIn Profile
lion batch urls.txt --output-dir ./resumes --headless
# Step 2:LLM 提取结构化 JSON
lion extract ./resumes --output ./json_output
API 接口说明
所有核心功能均可作为 Python 函数导入:
from linkedin_lion import login, scrape_profile, batch_scrape, extract_resume
# --- 单个抓取 ---
driver = login(cookie_file="cookie.json", headless=False)
text = scrape_profile(
driver,
profile_url="https://www.linkedin.com/talent/profile/ACoAAA...",
filename="resume.txt",
folder="./output",
)
driver.quit()
# --- 批量抓取 ---
batch_scrape(
filepath="urls.txt",
output_dir="./resumes",
headless=True,
start=0,
end=100,
cookie_file="cookie.json",
)
# --- LLM 提取 ---
extract_resume(
input_path="./resumes", # 目录或单个 .txt 文件
output_dir="./json_output",
max_retries=3,
prompt_template=None, # None 使用内置默认模板
)
配置 API
from linkedin_lion.config import load_config, get_llm_config
# 版本 A:最简配置,所有 LLM 参数均由 llmdog 内置默认值接管
cfg = load_config()
llm_kwargs = get_llm_config(cfg) # 返回 {},llmdog 自行处理所有默认值
# 版本 B:完整配置,显式覆盖全部参数
cfg = load_config(
api_key="sk-xxxx", # 可选
api_url="https://api.deepseek.com/v1/chat/completions", # 可选
model="deepseek-chat", # 可选
timeout=60, # 可选
verify_ssl=True, # 可选
cookie_file="cookie.json", # 可选
)
llm_kwargs = get_llm_config(cfg)
# 返回 {'api_key': ..., 'api_url': ..., 'model': ..., 'timeout': 60, 'verify_ssl': True}
依赖项清单
| 依赖 | 用途 |
|---|---|
typer[all]>=0.12 |
CLI 框架 |
rich>=13.0 |
终端美化输出 |
selenium |
浏览器自动化 |
browser-dog |
Selenium Cookie 登录封装 |
beautifulsoup4 |
HTML 文本提取 |
llmdog |
LLM 调用(chat 接口) |
larkfunc |
文件读写 / 文本处理工具函数 |
diskcache |
LinkedIn URN 本地缓存 |
python-dotenv |
.env 配置文件加载 |
贡献指南与许可证
贡献
- Fork 本仓库并创建功能分支
- 代码风格遵循项目内
DESIGN_SPEC.md规范(Typer + Rich,零裸 print) - 提交 PR 前确保代码通过基础导入测试
许可证
MIT License — 详见 LICENSE
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file linkedin_lion-0.0.1.tar.gz.
File metadata
- Download URL: linkedin_lion-0.0.1.tar.gz
- Upload date:
- Size: 32.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
062c0ab6d9fa2014eab422b0136668e9f0059504b372d399b74e7524a9e0baf1
|
|
| MD5 |
dddb4064dc12ddf647ce72736bc693ba
|
|
| BLAKE2b-256 |
e8329a69643b5a707c05dc42db7ffb8bee83ecc57f0ae3ad3201c6c06e03334c
|
File details
Details for the file linkedin_lion-0.0.1-py3-none-any.whl.
File metadata
- Download URL: linkedin_lion-0.0.1-py3-none-any.whl
- Upload date:
- Size: 21.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1ec1bb88cbba8c16fe8b9c1c80c303e18da8a477c6c146fc7ba261ec1029562e
|
|
| MD5 |
5ab0a55331fa7b044f6d8f48adcc17b0
|
|
| BLAKE2b-256 |
a0d6993146fc5366f7a47abcb2e4ec3d8e8fb71d39bf51c7f79e316ac9cb5291
|