基于 SOC 职业分类
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
直接命令不会经过审查 Prompt;运行前请先检查来源。
npx skills add https://github.com/zhizhunbao/ai-dev-config --skill web-scraping命令会保持在同一行。复制前请横向滚动并检查完整内容。
想先保存到本地?可下载 SkillsMP 当前能够提供的文件。
正在显示 SKILL.md
Complete software development lifecycle from requirements to deployment. Use when (1) starting a new project from scratch, (2) need structured end-to-end development process, (3) require comprehensive documentation and quality gates at each phase.
专业的AI Agent(AI Agents)顾问助手,探索 AI Agent 框架和应用。当用户询问以下问题时使用:(1) 技术选型和对比 (2) 使用指南和最佳实践 (3) 问题诊断和解决 (4) 资源推荐 (5) 常见问题解答
Comprehensive CV learning assistant. Use when studying image processing, object detection, segmentation, or any CV tasks. Helps with algorithm understanding, implementation, and model optimization.
| name | web-scraping |
| description | 网页抓取与数据提取。Use when (1) 需要抓取网页内容, (2) 绕过反爬虫机制, (3) 处理动态加载内容, (4) 批量采集数据, (5) 解析特定网站结构 |
Always use stealth configuration to avoid detection:
# Remove automation flags
context.add_init_script("""
Object.defineProperty(navigator, 'webdriver', {
get: () => undefined
});
""")
# Use realistic settings
browser = playwright.chromium.launch(
args=['--disable-blink-features=AutomationControlled']
)
Add random delays and smooth interactions:
import random
await asyncio.sleep(random.uniform(0.5, 2.0))
await page.mouse.move(x, y, steps=random.randint(10, 30))
Use appropriate wait strategies:
# For static content
await page.goto(url, wait_until='networkidle')
# For dynamic content
await page.wait_for_selector('.content')
await page.wait_for_function("document.querySelectorAll('.item').length > 10")
title = await page.locator('h1').first.text_content()
paragraphs = await page.locator('article p').all_text_contents()
content = '\n\n'.join(paragraphs)
while len(items) < max_items:
await page.evaluate("window.scrollTo(0, document.body.scrollHeight)")
await page.wait_for_timeout(2000)
current_items = await page.locator('.item').all()
if len(current_items) == previous_count:
break
# Close cookie banners and modals
try:
await page.click('button:has-text("Accept")', timeout=3000)
except:
pass
await page.fill('input[name="username"]', username)
await page.fill('input[name="password"]', password)
await page.click('button[type="submit"]')
await page.wait_for_url('**/dashboard')
cookies = await context.cookies() # Save for reuse
Implement rate limiting to avoid bans:
from tenacity import retry, stop_after_attempt, wait_exponential
@retry(stop=stop_after_attempt(3), wait=wait_exponential(min=4, max=10))
async def scrape_with_retry(url: str):
# Your scraping logic
pass
Track requests per time window:
class RateLimiter:
def __init__(self, max_requests: int, time_window: int):
self.max_requests = max_requests
self.time_window = time_window
self.requests = []
async def wait_if_needed(self):
# Remove old requests, wait if limit reached
pass
Use BeautifulSoup for parsing after Playwright renders:
from bs4 import BeautifulSoup
soup = BeautifulSoup(html, 'lxml')
# Remove unwanted elements
for element in soup(['script', 'style', 'nav', 'footer']):
element.decompose()
# Extract structured data
article = soup.find('article') or soup.find('main')
paragraphs = [p.get_text(strip=True) for p in article.find_all('p')]
Cache results to minimize requests:
import hashlib
import json
def get_cache_path(url: str) -> Path:
url_hash = hashlib.md5(url.encode()).hexdigest()
return Path(f'.cache/{url_hash}.json')
# Check cache before scraping
cached = load_from_cache(url)
if cached:
return cached
pip install playwright beautifulsoup4 lxml tenacity
playwright install chromium
# Or with uv
uv add playwright beautifulsoup4 lxml tenacity
uv run playwright install chromium
scripts/scrapers/
├── base.py # Base scraper class with stealth mode
├── extractors/ # Site-specific extractors
│ ├── medium.py
│ ├── github.py
│ └── generic.py
├── utils/
│ ├── stealth.py # Anti-bot utilities
│ ├── cache.py # Caching logic
│ └── rate_limit.py # Rate limiting
└── config.py # User agents, timeouts, etc.
Before deploying:
playwright install chromiumwait_until='domcontentloaded'wait_for_selector()For detailed code examples: See references/examples.md
For site-specific patterns: See references/patterns.md
For advanced anti-bot techniques: See references/stealth-guide.md