with one click
web-scraping
网页数据提取技能,使用 Playwright 进行动态内容抓取,处理反爬虫机制,数据清洗和结构化
Install with Codex or Claude Copy this prompt, paste it into Codex, Claude, or another assistant, and let it review the skill page and install it for you.
Menu
网页数据提取技能,使用 Playwright 进行动态内容抓取,处理反爬虫机制,数据清洗和结构化
Install with Codex or Claude Copy this prompt, paste it into Codex, Claude, or another assistant, and let it review the skill page and install it for you.
Based on SOC occupation classification
Use this skill when debugging complex, multi-factor, or long-running bugs. It maintains a project-root /coe Markdown case file per bug case using a strict Chain-of-Evidence model with only Problem, Hypothesis, and Evidence nodes.
Best practices for Remotion - Video creation in React
Manages shadcn components and projects — adding, searching, fixing, debugging, styling, and composing UI. Provides project context, component docs, and usage examples. Applies when working with shadcn/ui, component registries, presets, --preset codes, or any project with a components.json file. Also triggers for "shadcn init", "create an app with --preset", or "switch to --preset".
Use when the user needs to design, implement, audit, or govern Storybook stories for frontend components, design systems, page states, interaction tests, accessibility checks, visual baselines, or component-driven UI workflows.
Allows you to view the user's screen as well as several hours of history. Use when the user makes a reference to their recent work, for which it'd be helpful to see the screen. This skill MUST be used whenever you need to resolve ambiguity in a user request, where the user hasn't specified enough context to do the task. Examples include disambiguating the specific user/app/document/error the user is referring to. You must also use this skill if the user asks about any question regarding Chronicle or asks what you can see from the screen.
Use when a frontend redesign or legacy CSS refactor is blocked by global style pollution, selector collisions, unstable DOM reuse, or the need to migrate a page or module to a new UI without breaking the old system.
| name | web-scraping |
| description | 网页数据提取技能,使用 Playwright 进行动态内容抓取,处理反爬虫机制,数据清洗和结构化 |
本技能提供系统化的网页数据抓取方法,特别针对商业研究场景中的社交媒体、应用商店和论坛数据提取。
目标: 收集特定主题的用户讨论
步骤:
1. 使用 Playwright 访问 Reddit 子版块
2. 搜索关键词
3. 抓取热门帖子 (按 upvotes 排序)
4. 提取: 标题、内容、评论数、upvotes、发布时间
5. 存储到 SQLite
示例代码逻辑:
// 访问 Reddit
await page.goto('https://reddit.com/r/iPhone');
// 搜索关键词
await page.fill('input[name="q"]', 'battery anxiety');
await page.click('button[type="submit"]');
// 等待结果加载
await page.waitForSelector('.Post');
// 提取数据
const posts = await page.$$eval('.Post', posts => {
return posts.map(post => ({
title: post.querySelector('h3').textContent,
upvotes: post.querySelector('[data-test-id="post-upvote-count"]').textContent,
url: post.querySelector('a').href,
timestamp: post.querySelector('time').getAttribute('datetime')
}));
});
目标: 收集竞品的用户评论
步骤:
1. 访问 App Store 网页版
2. 滚动加载更多评论
3. 提取: 评分、评论内容、用户名、日期
4. 按评分分类存储
注意事项:
目标: 收集实时用户抱怨
步骤:
1. 搜索关键词
2. 按"最新"排序
3. 提取推文和互动数据
4. 过滤垃圾信息
反爬虫策略:
目标: 发现新兴竞品
步骤:
1. 访问特定类别页面
2. 提取产品列表
3. 收集: 产品名、描述、upvotes、评论数、链接
4. 分析趋势
原始数据: " Battery health dropped to 96%!!! 😱😱 "
清洗后: "Battery health dropped to 96%"
步骤:
- 去除前后空格
- 移除多余的标点符号
- 移除 emoji (可选)
- 统一大小写 (可选)
原始: "2 hours ago", "Jan 15, 2025", "2025-01-15T10:30:00Z"
标准化: "2025-01-15 10:30:00"
使用 ISO 8601 格式存储
原始: "1.2K upvotes", "5M downloads"
提取: 1200, 5000000
处理 K (千), M (百万), B (十亿)
基于内容相似度去重:
- 完全相同: 直接删除
- 高度相似 (>90%): 保留 upvotes 最高的
- 中度相似 (70-90%): 标记为相关
CREATE TABLE reddit_posts (
id INTEGER PRIMARY KEY AUTOINCREMENT,
subreddit TEXT,
title TEXT,
content TEXT,
author TEXT,
upvotes INTEGER,
comment_count INTEGER,
url TEXT UNIQUE,
created_at TEXT,
scraped_at TEXT,
category TEXT
);
CREATE TABLE reddit_comments (
id INTEGER PRIMARY KEY AUTOINCREMENT,
post_id INTEGER,
content TEXT,
author TEXT,
upvotes INTEGER,
created_at TEXT,
FOREIGN KEY (post_id) REFERENCES reddit_posts(id)
);
CREATE TABLE app_reviews (
id INTEGER PRIMARY KEY AUTOINCREMENT,
app_name TEXT,
app_id TEXT,
rating INTEGER,
review_title TEXT,
review_content TEXT,
reviewer_name TEXT,
review_date TEXT,
helpful_count INTEGER,
scraped_at TEXT
);
CREATE TABLE tweets (
id INTEGER PRIMARY KEY AUTOINCREMENT,
tweet_id TEXT UNIQUE,
content TEXT,
author TEXT,
likes INTEGER,
retweets INTEGER,
replies INTEGER,
created_at TEXT,
url TEXT,
scraped_at TEXT
);
规则:
- 每个请求间隔 1-3 秒 (随机)
- 每 10 个请求后暂停 5-10 秒
- 每小时不超过 100 个请求
使用真实的浏览器 User-Agent:
- Chrome on macOS
- Safari on iOS
- Firefox on Windows
避免使用明显的爬虫标识
如果需要大量抓取:
- 使用住宅代理
- 轮换 IP 地址
- 注意成本
保持会话状态:
- 保存 cookies
- 模拟登录 (如果需要)
- 处理验证码 (手动或服务)
页面加载超时
元素未找到
被封禁
数据格式变化
不要同时打开太多浏览器实例:
- 最多 3-5 个并发
- 使用队列管理任务
- 监控内存使用
避免重复抓取:
- 检查 URL 是否已存在
- 设置数据有效期
- 定期清理过期数据
只抓取新内容:
- 记录最后抓取时间
- 按时间过滤
- 减少不必要的请求
# [网站名称] 数据抓取报告
## 抓取概况
- 抓取时间: YYYY-MM-DD HH:MM:SS
- 目标网站: [URL]
- 抓取页面数: X
- 成功率: XX%
## 数据统计
- 总记录数: X
- 有效记录数: X
- 去重后: X
## 数据质量
- 完整性: XX%
- 准确性: 人工抽查 XX 条,准确率 XX%
## 遇到的问题
- [问题描述]
- [解决方案]
## 数据存储
- 数据库: research_data.db
- 表名: [table_name]
1. 定义目标
- 主题: iOS battery anxiety
- 子版块: r/iPhone, r/iOS
- 时间范围: 最近 6 个月
2. 执行抓取
- 使用 Playwright 访问 Reddit
- 搜索关键词
- 抓取 Top 50 帖子
- 抓取每个帖子的 Top 10 评论
3. 数据清洗
- 去除重复
- 标准化时间
- 提取关键信息
4. 数据存储
- 存入 SQLite
- 创建索引
5. 数据分析
- 痛点聚类
- 情感分析
- 趋势识别
6. 生成报告
- 抓取统计
- 关键发现
- 数据样本
# 重新安装浏览器
npx playwright install chromium
# 检查依赖
npx playwright install-deps
# 关闭所有连接
# 检查是否有其他进程在使用数据库
lsof research_data.db
- 减少并发数
- 及时关闭浏览器实例
- 清理临时数据