介绍
# LinkedIn Automation
> **作者:** 社区贡献者 > > ⚠️ **免责声明 —— 仅限个人使用** > 此技能**仅供个人、非商业用途**使用。它用于自动化您自己的 LinkedIn 账户,以提升个人生产力和互动。请勿将此技能用于垃圾信息、大规模群发、抓取其他用户数据或任何商业自动化服务。请负责任地使用,并遵守 [LinkedIn 用户协议](https://www.linkedin.com/legal/user-agreement)。作者对误用或账户限制不承担任何责任。
使用具有持久会话的无头 Playwright 浏览器自动化 LinkedIn 交互。
## 前置条件
- Python 3.10+ 并安装了 Playwright (`pip install playwright && playwright install chromium`) - 已登录的 LinkedIn 浏览器会话(持久化的 Chromium 配置文件) - 调整 `scripts/lib/browser.py` 中的路径以匹配您的设置
## 命令
```bash CLI={baseDir}/scripts/linkedin.py
# Check if session is valid python3 $CLI check-session
# Read feed python3 $CLI feed --count 5
# Create a post (text only) python3 $CLI post --text "Hello world"
# Create a post with image (handles LinkedIn's image editor modal automatically) python3 $CLI post --text "Hello world" --image /path/to/image.png
# Comment on a post (supports @Mentions — see below) python3 $CLI comment --url "https://linkedin.com/feed/update/..." --text "Great insight @Betina Weiler!"
# Edit a comment (match by text fragment) python3 $CLI edit-comment --url "https://..." --match "old text" --text "new text"
# Delete a comment python3 $CLI delete-comment --url "https://..." --match "text to identify"
# Repost with thoughts python3 $CLI repost --url "https://..." --thoughts "My take..."
# Engagement analytics for recent posts python3 $CLI analytics --count 10
# Profile-level stats (followers, views) python3 $CLI profile-stats
# Monitor your likes for new ones (for comment suggestions) python3 $CLI scan-likes --count 15
# Scrape someone's activity python3 $CLI activity --profile-url "https://linkedin.com/in/someone/" --count 5 ```
所有命令均输出 JSON。启用调试日志:`LINKEDIN_DEBUG=1`。
## @提及
评论支持 `@FirstName LastName` 语法。该技能: 1. 输入 `@FirstName` → 等待自动补全下拉菜单 2. 如有必要,逐个字母输入姓氏 3. 仅当名和姓都匹配时才点击匹配项 4. 如果未找到该人员,则回退到纯文本(返回 `mention_failed` 警告)
检查 JSON 结果中的 `mentions` 以查看提及是否成功。
## 点赞监控
`scan-likes` 命令检查您最近的点赞/反应活动,并返回自上次检查以来的任何**新点赞**。状态会被持久化以避免重复提醒。非常适合与 cron/heartbeat 集成:
``` # In HEARTBEAT.md or cron job: python3 $CLI scan-likes → if new likes found → suggest comment for each ```
## ⚠️ 黄金法则
**未经用户明确批准,切勿发布、评论、转发、编辑或删除任何内容。**
始终向用户确切展示将要发布的内容,并在执行前获得明确的“是”。只读操作(feed、analytics、check-session、scan-likes)可以安全运行。
## 内容日历(定时发布)
完整的基于审批的发布工作流,支持自动发布。有关设置,请参阅 **[references/content-calendar.md](references/content-calendar.md)**。
- **Webhook** (`scripts/cc-webhook.py`):接收来自前端 UI 的批准/编辑/跳过指令 - **自动应用**:简单编辑(`"old text -> new text"`)由 webhook 立即应用 - **Agent 处理**:复杂编辑被标记为 AI 驱动的文本重写 - **自动发布**:超过预定时间的已批准帖子将通过 cron 自动发布 - **图片策略**:真实照片 + AI 生成的故事叠加层(而非图库照片)
```bash # Start the webhook (or install as systemd service) python3 scripts/cc-webhook.py
# Env vars for config: # CC_DATA_FILE=/path/to/cc-data.json # CC_ACTIONS_FILE=/path/to/actions.json # CC_WEBHOOK_PORT=8401 ```
## 内容策略与互动
- **[references/content-strategy.md](references/content-strategy.md)** — 钩子公式、帖子结构、发布时间、话题标签策略、4-1-1 法则 - **[references/engagement.md](references/engagement.md)** — 算法信号、评论质量公式、速率限制、每周例行事项 - **[references/dom-patterns.md](references/dom-patterns.md)** — 已知的 LinkedIn DOM 模式,用于故障排除 - **[references/content-calendar.md](references/content-calendar.md)** — 内容日历设置、数据格式、webhook API
## 速率限制
| 操作 | 每日上限 | 每周上限 | |--------|----------|-----------| | 帖子 | 2–3 | 10–15 | | 评论 | 20–30 | — | | 点赞 | 100 | — | | 连接请求 | 30 | 100 |
## 设置
1. 安装依赖:`pip install playwright && playwright install chromium` 2. 在 `scripts/lib/browser.py` 中配置浏览器配置文件路径(或设置 `LINKEDIN_BROWSER_PROFILE` 环境变量) 3. 手动登录 LinkedIn 一次(会话将持久化) 4. 运行 `python3 scripts/linkedin.py check-session` 进行验证 5. **学习您的语调:** 运行 `python3 scripts/linkedin.py learn-profile` — 这会扫描您最近的帖子和评论,以学习您的语调、话题、语言和风格。Agent 在建议评论/帖子时会使用此配置文件,使其听起来像**您**,而不是通用的机器人。
## 语调与风格
在首次设置时,`learn-profile` 会分析您的内容并保存一个风格配置文件 (`~/.linkedin-style.json`),其中包含: - **语言**(de/en/mixed) - **语调**(casual / professional / professional-friendly) - **表情符号使用**(heavy / moderate / minimal) - 您常用的**热门话题标签** - 用于语调参考的**示例帖子和评论**
Agent 在起草任何评论或帖子建议之前,应该**始终**读取此配置文件 (`get-style`)。切勿施加生硬的语调 —— 匹配用户的自然风格。
## 帖子时效警告
**关键:** 在建议对任何帖子进行评论之前,请检查帖子的时效: - **< 2 周:** 可以安全评论 - **> 2 周:** 明确警告用户(“⚠️ 此帖子已发布 X 周 —— 评论旧帖子可能看起来像机器人行为。仍然要继续吗?”) - **> 1 个月:** 除非有特殊原因,否则强烈不建议
在旧帖子上评论会让您看起来像是在用机器人挖掘某人的历史记录。始终标记帖子时效。
## 故障排除
- **会话过期**:通过浏览器配置文件重新登录 - **选择器失效**:LinkedIn 频繁更新 UI —— 检查 `references/dom-patterns.md` 并更新 `scripts/lib/selectors.py` - **调试截图**:失败时保存到 `/tmp/linkedin_debug_*.png`