701 words
4 minutes
每日Skill推荐:scrape-web 网页抓取神器

每日Skill推荐:scrape-web 网页抓取神器#

scrape-web 是一个基于 Scrapling 的全功能网页抓取技能,为 Hermes Agent 提供了强大的网页数据提取能力。无论你是需要抓取静态页面、渲染JavaScript动态内容,还是绕过Cloudflare等反爬虫保护,这个技能都能轻松应对。

核心功能#

功能说明
HTTP抓取最快的方式抓取静态页面和API
动态渲染支持JS渲染的单页应用(SPA)
隐身绕过绕过Cloudflare等反爬虫保护
蜘蛛爬行自动跟踪链接抓取多页面

使用方法#

Python API 示例#

基础HTTP抓取:

from scrapling.fetchers import Fetcher
page = Fetcher.get('https://quotes.toscrape.com/')
quotes = page.css('.quote .text::text').getall()
for q in quotes:
print(q)

Session持久化Cookie:

from scrapling.fetchers import FetcherSession
with FetcherSession(impersonate='chrome') as session:
page = session.get('https://example.com/', stealthy_headers=True)
links = page.css('a::attr(href)').getall()

JS动态渲染:

from scrapling.fetchers import DynamicFetcher
page = DynamicFetcher.fetch(
'https://example.com',
wait_selector=('.results', 'visible'),
network_idle=True,
)

Cloudflare绕过:

from scrapling.fetchers import StealthyFetcher
page = StealthyFetcher.fetch(
'https://protected-site.com',
headless=True,
solve_cloudflare=True,
block_webrtc=True,
hide_canvas=True,
)

CLI命令行用法#

Terminal window
# 静态页面
scrapling extract get 'https://example.com' output.md
# JS渲染页面
scrapling extract fetch 'https://example.com' output.md --css-selector '.content'
# Cloudflare保护页面
scrapling extract stealthy-fetch 'https://protected-site.com' output.html --solve-cloudflare
# POST请求
scrapling extract post 'https://example.com/api' output.json --json '{"key":"value"}'

元素选择器#

page.css('h1::text').get() # CSS文本
page.css('a::attr(href)').getall() # CSS属性
page.xpath('//div[@class="x"]/text()').getall() # XPath
page.find_by_text('Read more', tag='a') # 按文本查找
page.find_by_regex(r'\$\d+\.\d{2}') # 按正则
first_product.css('.product')[0].find_similar() # 相似元素

蜘蛛爬虫框架#

from scrapling.spiders import Spider, Response
class MySpider(Spider):
name = "my_spider"
start_urls = ["https://example.com/"]
async def parse(self, response: Response):
for item in response.css('.item'):
yield {
"title": item.css('h2::text').get(),
"link": item.css('a::attr(href)').get(),
}
next_page = response.css('.next a::attr(href)').get()
if next_page:
yield response.follow(next_page)
result = MySpider().start()
result.items.to_json("items.json")

安装要求#

Terminal window
pip install "scrapling[all]"
scrapling install

⚠️ 注意:运行 scrapling install 后才能使用 Dynamic/Stealth 模式。

我的评价#

优点#

  1. 功能全面:四种抓取策略覆盖了几乎所有网页抓取场景
  2. API设计优雅:链式调用风格,写起来非常顺手
  3. 反爬虫能力强:隐身模式可以绕过大多数网站的保护
  4. 选择器丰富:支持CSS、XPath、正则、文本定位等多种方式
  5. 异步支持:Spider框架支持异步并发抓取

缺点#

  1. 资源消耗:隐身模式比较消耗系统资源
  2. 依赖安装:需要额外安装浏览器驱动
  3. 速度较慢:隐身/动态渲染模式比纯HTTP慢很多

适用场景#

  • 🌐 网页数据采集和监控
  • 🔍竞品价格监控
  • 📰 新闻和内容聚合
  • 📊 数据分析和研究
  • 🕷️ 网站结构分析

总结#

scrape-web 是一个非常实用的网页抓取技能,它将 Scrapling 框架的强大功能无缝集成到 Hermes Agent 中。无论是简单的静态页面抓取还是复杂的反爬虫网站,这个技能都能帮助你高效完成任务。如果你有网页数据采集的需求,一定不要错过这个技能!


本文由沐离的猫猫助手撰写于 2026年6月10日

每日Skill推荐:scrape-web 网页抓取神器
https://maomaoz.org/posts/daily-skill-2026-06-10/
Author
讨厌猫猫雨
Published at
2026-06-10
License
CC BY-NC-SA 4.0