Troubleshooting Computer Issues
用于系统性诊断和解决软件配置、安装错误及运行异常等问题。
下载 123
提供网页抓取的策略与最佳实践,支持反反爬机制和多模式执行。
openclaw skills install @devbd1/scrapling-web-scraping命令、参数、文件名以原文为准
引导层 + MCP 集成
本技能用于策略与模式设计。执行阶段请通过
mcporter调用 Scrapling 的 MCP 服务。
pip install scrapling[mcp]
# 或安装完整功能:
pip install scrapling[mcp,playwright]
python -m playwright install chromium{
"mcpServers": {
"scrapling": {
"command": "python",
"args": ["-m", "scrapling.mcp"]
}
}
}mcporter call scrapling fetch_page --url "https://example.com"| 任务 | 工具 | 示例 |
|---|---|---|
| 获取页面内容 | mcporter | mcporter call scrapling fetch_page --url URL |
| 使用 CSS 提取数据 | mcporter | mcporter call scrapling css_select --selector ".title::text" |
| 应该使用哪个抓取器? | 本技能 | 参见下方“抓取器选择指南” |
| 遇到反爬策略? | 本技能 | 参见“反爬升级阶梯” |
| 复杂爬取模式? | 本技能 | 参见“蜘蛛配方” |
┌─────────────────┐ ┌──────────────────┐ ┌──────────────────┐
│ 抓取器 │────▶│ 动态抓取器 │────▶│ 隐蔽抓取器 │
│ (HTTP) │ │ (浏览器/JS 渲染) │ │ (反反爬) │
└─────────────────┘ └──────────────────┘ └──────────────────┘
最快 JS 渲染页面 Cloudflare、Turnstile 等
静态页面 SPA、React/Vue 常见反爬挑战Fetcher(速度提升 10–100 倍)DynamicFetcherStealthyFetcherfetch_page — HTTP 抓取器fetch_dynamic — 基于 Playwright 的浏览器抓取fetch_stealthy — 反反爬绕过模式# MCP 调用:fetch_page 并配置选项
{
"url": "https://example.com",
"headers": {"User-Agent": "..."},
"delay": 2.0
}# 使用会话保持 Cookie / 状态
FetcherSession(impersonate="chrome") # 模拟浏览器 TLS 指纹# MCP 调用:fetch_stealthy
StealthyFetcher.fetch(
url,
headless=True,
solve_cloudflare=True, # 自动解决 Turnstile
network_idle=True
)详见 references/proxy-rotation.md
Scrapling 可通过自适应选择器应对网站结构变更:
# 首次运行 —— 保存 DOM 特征指纹
products = page.css('.product', auto_save=True)
# 后续运行 —— 若 DOM 结构变化,自动重新定位
products = page.css('.product', adaptive=True)MCP 使用方式:
mcporter call scrapling css_select \\
--selector ".product" \\
--adaptive true \\
--auto-save true何时使用蜘蛛 vs 直接抓取:
from scrapling.spiders import Spider, Response
class ProductSpider(Spider):
name = "products"
start_urls = ["https://example.com/products"]
concurrent_requests = 10
download_delay = 1.0
async def parse(self, response: Response):
for product in response.css('.product'):
yield {
"name": product.css('h2::text').get(),
"price": product.css('.price::text').get(),
"url": response.url
}
# 处理分页
next_page = response.css('.next a::attr(href)').get()
if next_page:
yield response.follow(next_page)
# 启动并支持断点续爬
result = ProductSpider(crawldir="./crawl_data").start()
result.items.to_jsonl("products.jsonl")from scrapling.spiders import Spider, Request, Response
from scrapling.fetchers import FetcherSession, AsyncStealthySession
class MultiSessionSpider(Spider):
name = "multi"
start_urls = ["https://example.com/"]
def configure_sessions(self, manager):
manager.add("fast", FetcherSession(impersonate="chrome"))
manager.add("stealth", AsyncStealthySession(headless=True), lazy=True)
async def parse(self, response: Response):
for link in response.css('a::attr(href)').getall():
if "/protected/" in link:
yield Request(link, sid="stealth")
else:
yield Request(link, sid="fast")crawldir 参数保存检查点async for item in spider.stream() 实时处理数据to_json()、to_jsonl() 导出方法# 提取为 Markdown
scrapling extract get 'https://example.com' content.md
# 提取特定元素
scrapling extract get 'https://example.com' content.txt \\
--css-selector '.article' \\
--impersonate 'chrome'
# 隐蔽模式
scrapling extract stealthy-fetch 'https://protected.com' content.md \\
--no-headless \\
--solve-cloudflarescrapling shell
# 在 Shell 中操作:
>>> page = Fetcher.get('https://example.com')
>>> page.css('h1::text').get()
>>> page.find_all('div', class_='item')# 通过属性查找
page.find_all('div', {'class': 'product', 'data-id': True})
page.find_all('div', class_='product', id=re.compile(r'item-\\d+'))
# 文本搜索
page.find_by_text('添加到购物车', tag='button')
page.find_by_regex(r'\\$\\d+\\.\\d{2}')
# 导航
first = page.css('.product')[0]
parent = first.parent
siblings = first.next_siblings
children = first.children
# 相似性匹配
similar = first.find_similar() # 查找视觉或结构上相似的元素
below = first.below_elements() # DOM 中位于其下方的元素# 获取任意元素的稳定选择器
element = page.css('.product')[0]
selector = element.auto_css_selector() # 返回稳定的 CSS 路径
xpath = element.auto_xpath()from scrapling.spiders import ProxyRotator
# 循环轮换
rotator = ProxyRotator([
"http://proxy1:8080",
"http://proxy2:8080",
"http://user:pass@proxy3:8080"
], strategy="cyclic")
# 与任意会话结合使用
with FetcherSession(proxy=rotator.next()) as session:
page = session.get('https://example.com')# 页码分页
for page_num in range(1, 11):
url = f"https://example.com/products?page={page_num}"
...
# 下一页按钮
while next_page := response.css('.next a::attr(href)').get():
yield response.follow(next_page)
# 无限滚动(DynamicFetcher)
with DynamicSession() as session:
page = session.fetch(url)
page.scroll_to_bottom()
items = page.css('.item').getall()with StealthySession(headless=False) as session:
# 登录
login_page = session.fetch('https://example.com/login')
login_page.fill('input[name="username"]', 'user')
login_page.fill('input[name="password"]', 'pass')
login_page.click('button[type="submit"]')
# 现在会话已携带 Cookie
protected_page = session.fetch('https://example.com/dashboard')# 提取 __NEXT_DATA__ 中的 JSON
import json
import re
next_data = json.loads(
re.search(
r'__NEXT_DATA__" type="application/json">(.*?)</script>',
page.html_content,
re.S
).group(1)
)
props = next_data['props']['pageProps']# JSON(美化输出)
result.items.to_json('output.json')
# JSONL(流式输出,每行一个)
result.items.to_jsonl('output.jsonl')
# Python 对象
for item in result.items:
print(item['title'])impersonate='chrome' 实现 TLS 指纹伪装http3=Truedisable_resources=Truedownload_delay)references/mcp-setup.md — 详细的 MCP 配置说明references/anti-bot.md — 反爬虫策略处理方法references/proxy-rotation.md — 代理配置与轮换方案references/spider-recipes.md — 高级爬取模式示例references/api-reference.md — 快速 API 参考手册references/links.md — 官方文档链接汇总scripts/scrapling_scrape.py — 快速一次性数据提取脚本scripts/scrapling_smoke_test.py — 测试连接性及反爬指标已收录 1 个 Skill