Scrapling:自适应网页爬虫框架
抖音博主”AI瑾观”的《一天一个宝藏工具》第19期介绍了一个爬虫工具——Scrapling,当天登上 GitHub Trending 第一名。它最特别的地方:网站页面结构怎么改版,都能自动重新定位元素,不需要手动改代码。
它是什么
Scrapling 是一个 Python 的 Web Scraping(网页爬取)框架,作者是 D4Vinci。一个库同时搞定三件事:
🕷️ Fetcher 抓取:普通 HTTP 请求(可模拟浏览器 TLS 指纹)、动态页面浏览器自动化、以及能自动绕过 Cloudflare Turnstile 等反机器人系统的隐秘抓取。
🎯 解析器会学习:它的 CSS/XPath 解析器带有智能相似度算法,网站改版后能自动重新定位你的元素——这就是视频里说的”页面结构怎么调都能精准抓取”。
🕸️ Spider 框架:类 Scrapy 的爬虫 API,支持并发、多 Session、暂停恢复、自动代理轮换,几行代码就能扩展成大规模爬取。
官网与仓库
官网:https://scrapling.app/
GitHub:https://github.com/D4Vinci/Scrapling
文档:https://scrapling.readthedocs.io/
PyPI:https://pypi.org/project/scrapling/
安装方法
需要 Python 3.10 以上:
pip install scrapling
要用抓取和爬虫功能,再装浏览器依赖:
pip install "scrapling[fetchers]"
scrapling install
一次性装全(含 MCP、命令行等):
pip install "scrapling[all]"
也可以用 Docker:
docker pull pyd4vinci/scrapling
快速上手
抓一个网页并提取数据(带自适应,网站改版也不怕):
from scrapling.fetchers import StealthyFetcher
StealthyFetcher.adaptive = True
p = StealthyFetcher.fetch('https://example.com', headless=True, network_idle=True)
items = p.css('.product', adaptive=True)
或者写一个完整爬虫:
from scrapling.spiders import Spider
class MySpider(Spider):
name = "demo"
start_urls = ["https://example.com/"]
async def parse(self, response):
for item in response.css('.product'):
yield {"title": item.css('h2::text').get()}
MySpider().start()
结果可以用内置导出直接存文件:items.to_json()、to_csv()、to_xml()。
视频里的亮点
🏆 当天 GitHub Trending 第一名的仓库
🔓 开箱即用绕过 Cloudflare Turnstile 反爬
🧠 网站改版自动重新定位元素,不用改代码
🚀 也提供命令行模式,不写代码也能抓 URL
视频来源:抖音 AI瑾观《一天一个宝藏工具》第19期。已下载无水印高清版存档。