🔍 LinkedIn个人资料抓取器-MCP服务器
用于自动发现LinkedIn个人资料和提取数据的高级模型上下文协议(MCP)服务器。按职业搜索专业人士,提取详细的个人资料信息,并导出到Excel-所有这些都通过统一的API。
✨ 特性
🎯 智能配置文件发现
- 谷歌搜索集成:使用Serper API查找LinkedIn个人资料
- 多查询策略:采用多种搜索模式以获得全面的结果
- 智能URL验证:过滤和验证LinkedIn个人资料URL
- 基于职业的搜索:目标特定角色(人工智能工程师、人力资源经理等)
- 批处理:在一次操作中搜索多个职业
📊 全面的数据提取
- 配置文件信息:名称、标题、地点、行业
- 当前位置:职位、公司、地点、日期
- 联系方式:电子邮件、电话(如有)、网站
- 专业统计:连接数、关注者数
- 技能:顶尖技能和专业领域
- 教育:学校、学位、研究领域
- 体验历程:完整的工作经历
🔧 MCP服务器工具
- 搜索_专业_档案:查找单一职业的个人资料
- 搜索_多种职业:跨多个角色进行批量搜索
- export_to_excel:将数据保存到格式化的Excel电子表格
- get_current结果:查看收集的配置文件摘要
- clear_results:重置收集的数据
💾 数据导出
- 卡通月历:专业格式的电子表格
- 时间戳:使用时间戳自动命名文件
- 自定义命名:可选自定义文件名
- 丰富的数据:每个配置文件包含15+个字段
- Pandas集成:数据操作简单
📋 需求
系统要求
- Python 3.8或更高版本
- Internet连接
- API密钥(RapidAPI、Serper)
Python依赖关系
httpx>=0.24.0
pandas>=2.0.0
openpyxl>=3.1.0
python-dotenv>=1.0.0
mcp>=0.1.0
fastmcp>=0.1.0API要求
- 无效账户 -对于LinkedIn个人资料数据API
- Serper API密钥 -谷歌搜索功能
🔧 安装
1.克隆或下载
git clone https://github.com/yourusername/linkedin-scraper-mcp.git
cd linkedin-scraper-mcp2.安装依赖项
pip install httpx pandas openpyxl python-dotenv mcp fastmcp或使用requirements.txt:
pip install -r requirements.txt3.设置API密钥
获取RapidAPI密钥
- 访问 RapidAPI.com 网站
- 注册一个免费帐户
- 订阅 最新LinkedIn个人资料数据API
- 从仪表板复制API密钥
获取Serper API密钥
- 访问 Serper.dev
- 注册一个帐户(提供免费等级)
- 从仪表板获取API密钥
4.配置环境变量
创建一个 .env 项目目录中的文件:
RAPIDAPI_KEY=your_rapidapi_key_here
SERPER_API_KEY=your_serper_api_key_here安全说明:永远不要承诺你的 .env 文件到版本控制!
添加到 .gitignore:
.env
*.xlsx
__pycache__/
*.pyc🚀 用法
作为MCP服务器运行
python linkedin_scraper.py服务器将以stdio模式启动,准备接收MCP工具调用。
以独立脚本运行
取消对底部测试函数的注释:
if __name__ == "__main__":
# Uncomment to test
asyncio.run(test_enhanced_scraper())
# Comment out for testing
# mcp.run(transport="stdio")然后运行:
python linkedin_scraper.py使用MCP工具
1.搜索单一职业
# Find AI Engineers
result = await search_profession_profiles(
profession="AI Engineer",
max_profiles=10
)2.搜索多个职业
# Find multiple roles at once
result = await search_multiple_professions(
professions="AI Engineer,HR Manager,Startup Founder",
max_profiles_per_profession=5
)3.导出到Excel
# Export with auto-generated filename
result = await export_to_excel()
# Export with custom filename
result = await export_to_excel(filename="my_contacts.xlsx")4.获取当前结果
# View summary of collected data
summary = await get_current_results()
print(summary)5.清除数据
# Clear all collected profiles
result = await clear_results()📊 输出格式
Excel电子表格列
| 列 | 说明 | 示例 |
|---|---|---|
| 姓名 | 全名 | John Doe |
| 领英个人资料 | 个人资料网址 | LinkedIn.com/in/johndoe |
| 电子邮件 | 电子邮件地址 | john@example.com |
| 电话 | 电话号码 | +1-555-0123 |
| 标题 | 专业标题 | 科技公司高级人工智能工程师 |
| 现任公司 | 现任雇主 | 科技公司 |
| 当前职位 | 当前职称 | 高级人工智能工程师 |
| 地点 | 地理位置 | 加利福尼亚州旧金山 |
| 工业 | 工业部门 | 计算机软件 |
| 网站 | 个人/公司网站 | johndoe.com |
| 连接数 | 连接数 | 500+ |
| 关注者 | 关注人数 | 1234 |
| 技能 | 顶级技能(逗号分隔) | Python、ML、TensorFlow |
| 搜索职业 | 使用搜索查询 | AI工程师 |
| 搜索排名 | 结果位置 | 1 |
| 报废时间 | 时间戳 | 2025-01-15 10:30:00 |
JSON响应格式
{
"full_name": "John Doe",
"first_name": "John",
"last_name": "Doe",
"headline": "Senior AI Engineer | Machine Learning Expert",
"location": "San Francisco Bay Area",
"country": "United States",
"industry": "Computer Software",
"linkedin_url": "https://linkedin.com/in/johndoe",
"profile_id": "johndoe",
"website": "https://johndoe.com",
"email": "john@example.com",
"phone": "+1-555-0123",
"current_position": {
"title": "Senior AI Engineer",
"company": "Tech Corp",
"location": "San Francisco, CA",
"start_date": "2023-01",
"end_date": ""
},
"company": "Tech Corp",
"skills": ["Python", "Machine Learning", "TensorFlow", "PyTorch"],
"connections_count": 500,
"followers_count": 1234,
"education": [
{
"school": "Stanford University",
"degree": "Master of Science",
"field_of_study": "Computer Science"
}
],
"profession_searched": "AI Engineer",
"search_rank": 1,
"scrape_timestamp": "2025-01-15T10:30:00"
}⚙️ 配置
调整搜索参数
搜索查询数
修改 search_queries 列入 search_google_for_linkedin_profiles:
search_queries = [
f'site:linkedin.com/in "{profession}" -dir',
f'"{profession}" LinkedIn profile site:linkedin.com/in',
f'linkedin.com/in {profession} professional',
f'{profession} site:linkedin.com/in USA', # Add more
f'intitle:"{profession}" site:linkedin.com/in' # Add more
]速率限制
调整请求之间的延迟:
# In process_profession
await asyncio.sleep(2) # Delay between profiles (default: 2 seconds)
# In search_multiple_professions
await asyncio.sleep(3) # Delay between professions (default: 3 seconds)自定义数据字段
包含更多LinkedIn数据
修改中的参数 get_linkedin_data:
params = {
"linkedin_url": linkedin_url,
"include_skills": "true",
"include_certifications": "true", # Changed to true
"include_publications": "true", # Changed to true
"include_honors": "true", # Changed to true
"include_volunteers": "true", # Changed to true
"include_projects": "true", # Changed to true
}自定义Excel列
编辑 save_to_excel 方法:
row = {
'Name': result.get('full_name', ''),
'LinkedIn Profile': result.get('linkedin_url', ''),
# Add custom columns
'Years of Experience': calculate_experience(result),
'Education Level': get_highest_degree(result),
'Custom Field': result.get('custom_data', '')
}更改搜索位置
修改Serper API有效载荷:
payload = {
'q': query,
'num': num_results,
'hl': 'en',
'gl': 'us', # Change country code (us, uk, ca, au, etc.)
'location': 'San Francisco, CA' # Add specific location
}🏗️ 建筑
构件图
┌─────────────────────────────────────────────┐
│ MCP Server Interface │
│ • search_profession_profiles │
│ • search_multiple_professions │
│ • export_to_excel │
│ • get_current_results │
│ • clear_results │
└──────────────────┬──────────────────────────┘
│
▼
┌─────────────────────────────────────────────┐
│ LinkedInScraper Class │
│ • Profile discovery │
│ • Data extraction │
│ • Result management │
└──────────────────┬──────────────────────────┘
│
┌─────────┴─────────┐
│ │
▼ ▼
┌─────────────────┐ ┌──────────────────┐
│ Serper API │ │ RapidAPI │
│ (Google Search)│ │ (LinkedIn Data) │
└─────────────────┘ └──────────────────┘
│ │
└─────────┬─────────┘
│
▼
┌─────────────────┐
│ Data Processing │
│ • Extraction │
│ • Validation │
│ • Formatting │
└────────┬─────────┘
│
▼
┌─────────────────┐
│ Excel Export │
│ (Pandas/OpenPyXL)│
└──────────────────┘数据流
1. User Request
↓
2. Search Google (Serper API)
• Multiple search queries
• Extract LinkedIn URLs
↓
3. Validate URLs
• Check format
• Remove duplicates
↓
4. Fetch Profile Data (RapidAPI)
• Get detailed profile info
• Rate limiting (2s delay)
↓
5. Extract Contact Info
• Parse JSON response
• Extract email patterns
• Structure data
↓
6. Store Results
• Add to results list
• Track metadata
↓
7. Export to Excel
• Format as DataFrame
• Save to .xlsx file🎯 用例
招聘与人才引进
# Find potential candidates
await search_multiple_professions(
professions="Senior Python Developer,Machine Learning Engineer,Data Scientist",
max_profiles_per_profession=20
)
await export_to_excel("tech_candidates.xlsx")2.销售和潜在客户开发
# Find decision makers
await search_multiple_professions(
professions="CTO,VP Engineering,Head of AI",
max_profiles_per_profession=15
)
await export_to_excel("tech_leads.xlsx")3.市场调研
# Research industry professionals
await search_profession_profiles(
profession="Blockchain Developer",
max_profiles=50
)
await export_to_excel("blockchain_market_research.xlsx")4.网络和伙伴关系
# Find potential collaborators
await search_multiple_professions(
professions="Startup Founder,Angel Investor,Venture Capitalist",
max_profiles_per_profession=10
)
await export_to_excel("potential_partners.xlsx")5.竞争情报
# Research competitors' teams
await search_profession_profiles(
profession="AI Engineer at OpenAI",
max_profiles=30
)
await export_to_excel("competitor_analysis.xlsx")🛠️ 故障排除
API关键问题
错误:“未设置RAPIDA_KEY”
# Check your .env file exists
ls -la .env
# Verify contents
cat .env
# Ensure no extra spaces
RAPIDAPI_KEY=your_key_here # ✓ Correct
RAPIDAPI_KEY = your_key_here # ✗ Wrong (spaces)错误:“无效的API密钥”
- 验证密钥是否正确(从仪表板复制粘贴)
- 检查API订阅是否处于活动状态
- 确保不超过免费等级限制
速率限制
错误:“429请求太多”
# Increase delays
await asyncio.sleep(5) # Instead of 2
# Reduce batch size
max_profiles=5 # Instead of 10未找到结果
问题:搜索返回空列表
# Try different search terms
"AI Engineer" → "Artificial Intelligence Engineer"
"HR Manager" → "Human Resources Manager"
# Be more specific
"Developer" → "Senior Python Developer"
# Add location
"Data Scientist in San Francisco"未找到电子邮件
问题:大多数配置文件显示“不可用”
这是意料之中的!LinkedIn不会公开显示大多数用户的电子邮件。仅在以下情况下提取电子邮件:
- 用户在“关于”部分包含电子邮件
- 电子邮件为标题或摘要
- 个人资料中有可见的联系信息
解决方法:
# Use other contact methods
- LinkedIn messaging
- Company website contact forms
- Twitter/social media handles
- GitHub profile (for developers)Excel导出问题
错误:“没有名为'openpyxl'的模块”
pip install openpyxl错误:“权限被拒绝”
# File is open in Excel - close it first
# Or use different filename
await export_to_excel("contacts_v2.xlsx")内存问题
错误:大批量出现“MemoryError”
# Process in smaller batches
for i in range(0, 100, 10):
await search_profession_profiles(
profession="Engineer",
max_profiles=10
)
await export_to_excel(f"batch_{i}.xlsx")
await clear_results() # Free memory🔒 隐私和法律考虑
重要说明
⚠️ 负责任地使用:此工具仅用于合法的商业目的
遵守法律
- ✅ 尊重LinkedIn ToS:查看LinkedIn的服务条款
- ✅ GDPR合规:如果针对欧盟个人资料,请确保符合GDPR
- ✅ CAN-SPAM:如果用于外联,请遵守电子邮件营销法
- ✅ 数据保护:安全地存储收集的数据
- ✅ 速率限制:遵守API费率限制
最佳实践
- 同意:在发送营销电子邮件之前获得同意
- 数据安全:加密存储的数据
- 有限保留:删除不再需要的数据
- 透明度:明确数据收集
- 退出:提供简单的退出机制
禁止使用
- ❌ 垃圾邮件或未经请求的营销
- ❌ 未经同意出售数据
- ❌ 骚扰或跟踪
- ❌ 违反LinkedIn服务条款
- ❌ 假冒或欺诈
📊 性能指标
速度基准
- 搜索时间:每个搜索查询约5-10秒
- 档案提取:每个配置文件约2-3秒
- 总时间:10个配置文件约30-40秒
- 批处理:100个配置文件约5-7分钟
API限值
Serper API(免费层)
- 每月2500次搜索
- 每个职业约25-30次搜索
- 每月可以找到约80-100个职业
RapidAPI(基本计划)
- 每月500个请求
- 每个配置文件1个请求
- 每月可以抓取约500个配置文件
优化提示
- 批处理:将类似职业分组
- 缓存结果:避免重新刮擦相同的轮廓
- 并行处理:有效地使用asyncio
- 智能查询:使用有针对性的搜索词
🤝 贡献
欢迎投稿!需要改进的地方:
特色创意
- \[\]添加对公司页面抓取的支持
- \[\]实施个人资料评分/排名
- \[\]添加电子邮件验证服务
- \[\]创建web仪表板界面
- \[\]添加CSV导出选项
- \[\]实现数据库存储(SQLite/PPostgreSQL)
- \[\]添加配置文件重复数据删除
- \[\]创建Docker容器
- \[\]添加webhook通知
- \[\]实现具有指数退避的重试逻辑
开发设置
# Clone repository
git clone https://github.com/yourusername/linkedin-scraper-mcp.git
# Create virtual environment
python -m venv venv
source venv/bin/activate # Linux/Mac
# or
venv\Scripts\activate # Windows
# Install dependencies
pip install -r requirements-dev.txt
# Run tests
pytest tests/
# Submit PR📝 许可证
此项目根据MIT许可证获得许可-有关详细信息,请参阅许可证文件。
🙏 致谢
- FastMCP:模型上下文协议服务器框架
- 拉皮达皮:API市场和全新LinkedIn个人资料数据API
- Serper:谷歌搜索API服务
- 熊猫:数据操作和分析
- HTTPX:现代HTTP客户端
📞 支持
获取帮助
- 问题:通过GitHub问题报告bug
- 讨论:在GitHub讨论中提问
- 文档:查看MCP文件 模型上下文协议.io
联系
- 电子邮件: your.email@example.com
- 推特:@yourusername:
- 领英:linkedin.com/in/yourprofile
🗺️ 路线图
2025年第一季度
- \[x\] 基本轮廓刮削
- \[x\] Excel导出
- \[x\] 多职业搜索
- \[\]电子邮件验证集成
- \[\]个人资料评分系统
2025年第二季度
- \[\]Web仪表板
- \[\]PostgreSQL集成
- \[\]高级过滤
- \[\]API认证
- \[\]Webhook支持
2025年第3季度
- \[\]公司页面抓取
- \[\]职位发布提取
- \[\]技能差距分析
- \[\]Chrome扩展程序
- \[\]移动应用程序
2025年第四季度
- \[\]人工智能驱动的匹配
- \[\]CRM集成
- \[\]分析仪表板
- \[\]团队协作功能
- \[\]企业功能
💡 提示和最佳实践
搜索优化
- 具体:“Python高级后端工程师”与“工程师”
- 使用标题:实际职位最有效
- 位置:添加目标结果的位置
- 工业:包括行业关键字
- 公司:按公司名称搜索特定信息
数据质量
- 验证电子邮件:使用电子邮件验证服务
- 交叉引用:检查多个来源
- 定期更新:LinkedIn个人资料更改
- 人工审核:手动验证重要联系人
API管理
- 监视器使用情况:跟踪API调用计数
- 升级计划:达到限制时升级
- 缓存结果:存储结果以避免重新获取
- 错误处理:实施稳健的错误处理
导出最佳实践
- 常规出口:经常导出数据
- 描述性名称:使用清晰的文件名
- 备份数据:保留多份副本
- 版本控制:跟踪数据版本
______________________________________________________________________
由...制作❤️ 用于专业网络和招聘
*星⭐ 如果你觉得这个仓库有用的话!*
______________________________________________________________________
📸 截图
Excel输出示例
| Name | LinkedIn Profile | Email | Current Position |
|---------------|---------------------------|--------------------|-------------------------|
| John Doe | linkedin.com/in/johndoe | john@example.com | Senior AI Engineer |
| Jane Smith | linkedin.com/in/janesmith | Not Available | Machine Learning Lead |
| Bob Johnson | linkedin.com/in/bobjohnson| bob@company.com | Data Scientist |汇总输出
{
"total_profiles": 25,
"professions": {
"AI Engineer": 10,
"Data Scientist": 8,
"ML Engineer": 7
},
"profiles_with_email": 6,
"profiles_with_phone": 2
}______________________________________________________________________
🔐 安全最佳实践
- 从不提交API密钥:使用.env和.gitignore
- 旋转按键:定期更改API密钥
- 限制访问:限制具有API凭据的用户
- 监视器使用情况:注意异常活动
- 安全存储:加密导出的数据
- 访问控制:实现用户身份验证
- 审计日志:跟踪所有API使用情况
- 数据保留:定期删除旧数据
______________________________________________________________________
免责声明:此工具仅用于教育和合法商业目的。始终遵守LinkedIn的服务条款、适用法律和法规。作者不对误用此工具负责。
