闪电般快速、智能且难以被检测的网页爬虫库Scrapling

项目简介

Scrapling 是一个高性能、智能的 Python 网络爬虫库,它能够自动适应网站变化,同时显著优于流行的替代品。对于初学者和专家,Scrapling 提供了强大的功能,同时保持了简洁性。

>> from scrapling.defaults import Fetcher, AsyncFetcher, StealthyFetcher, PlayWrightFetcher# Fetch websites' source under the radar!>> page = StealthyFetcher.fetch('https://example.com', headless=True, network_idle=True)>> print(page.status)200>> products = page.css('.product', auto_save=True)  # Scrape data that survives website design changes!>> # Later, if the website structure changes, pass `auto_match=True`>> products = page.css('.product', auto_match=True)  # and Scrapling still finds them!

Scrapeless 是您的全能网页抓取工具包,仅需每 1k 个 URL 仅需 0.60 美元!

  • 🚀 爬虫 API:通过单次 API 调用轻松且高度可定制的数据提取,从任何网站提供结构化数据。

  • ⚡ 爬虫浏览器:AI 驱动和LLM-驱动,它通过真实的指纹和无头浏览器支持模拟人类行为,确保无缝、无阻塞的抓取。

  • 🔒 网络解锁器:实时绕过验证码、IP 封锁和动态内容,确保无间断访问。

  • 代理:使用高质量、可旋转的代理来抓取亚马逊、Shopee 等顶级平台,覆盖 195 多个国家。

  • 💼 企业级:针对大规模和复杂数据需求的定制解决方案。

  • 🎁 免费试用:先试后买——亲身体验我们的服务。

  • 按使用付费:灵活、经济实惠的定价,无需长期承诺。

  • 轻松集成:无缝集成到您现有的工具和工作流程中,实现无烦恼的自动化。


关键特性

异步支持,按需抓取网站

  • HTTP 请求:使用 Fetcher 类进行快速且隐蔽的 HTTP 请求。

  • 动态加载与自动化:通过您的真实浏览器、Scrapling 的隐身模式、Playwright 的 Chrome 浏览器或 NSTbrowser 的无头浏览器,使用 PlayWrightFetcher 类抓取动态网站!

  • 反机器人保护绕过:轻松绕过保护,使用 StealthyFetcher 和 PlayWrightFetcher 类。


自适应抓取

  • 智能元素跟踪:在网站更改后重新定位元素,使用智能相似性系统和集成存储。

  • 🎯 灵活选择:CSS 选择器、XPath 选择器、基于过滤器的搜索、文本搜索、正则表达式搜索等。

  • 🔍 查找相似元素:自动定位与您找到的元素相似的元素!

  • 智能内容抓取:使用 Scrapling 强大的功能从多个网站提取数据,无需特定选择器。


高性能

  • 🚀闪电般快速:从头开始构建,以性能为核心,超越大多数流行的 Python 抓取库。

  • 电池高效:优化数据结构以实现最小内存占用。

  • ⚡ 快速 JSON 序列化:比标准库快 10 倍。


开发者友好

  • 🛠️ 强大的导航 API:轻松实现所有方向的 DOM 遍历。

  • 富文本处理:所有字符串都内置正则表达式、清理方法等。所有元素的属性都是优化过的字典,比标准字典占用更少的内存,并增加了方法。

  • 自动选择器生成:为任何元素生成强大、简洁的短和完整 CSS/XPath 选择器。

  • 🔌 熟悉的 API:类似于 Scrapy/BeautifulSoup,并使用与 Scrapy 相同的伪元素。

  • 类型提示:为未来保障和最佳自动补全支持提供完整的类型/文档字符串覆盖。


开始使用

from scrapling import Fetcher
fetcher = Fetcher(auto_match=False)
# Do http GET request to a web page and create an Adaptor instancepage = fetcher.get('https://quotes.toscrape.com/', stealthy_headers=True)# Get all text content from all HTML tags in the page except `script` and `style` tagspage.get_all_text(ignore_tags=('script', 'style'))
# Get all quotes elements, any of these methods will return a list of strings directly (TextHandlers)quotes = page.css('.quote .text::text') # CSS selectorquotes = page.xpath('//span[@class="text"]/text()') # XPathquotes = page.css('.quote').css('.text::text') # Chained selectorsquotes = [element.text for element in page.css('.quote .text')] # Slower than bulk query above
# Get the first quote elementquote = page.css_first('.quote') # same as page.css('.quote').first or page.css('.quote')[0]
# Tired of selectors? Use find_all/find# Get all 'div' HTML tags that one of its 'class' values is 'quote'quotes = page.find_all('div', {'class': 'quote'})# Same asquotes = page.find_all('div', class_='quote')quotes = page.find_all(['div'], class_='quote')quotes = page.find_all(class_='quote') # and so on...
# Working with elementsquote.html_content # Get Inner HTML of this elementquote.prettify() # Prettified version of Inner HTML abovequote.attrib # Get that element's attributesquote.path # DOM path to element (List of all ancestors from <html> tag till the element itself)

项目链接

https://github.com/D4Vinci/Scrapling

扫码加入技术交流群,备注开发语言-城市-昵称

(文:GitHubStore)

欢迎分享

发表评论