# 网络爬虫

网络爬虫是一种自动化HTTP客户端，它无需人工逐条发起请求，即可跨一个或多个网站抓取资源，并在抓取页面的过程中发现新的URI，将其调度以便后续处理。<sup>[1](https://www.potaroo.net/ietf/ids/draft-illyes-aipref-cbcp-04.txt)</sup> 爬虫为搜索引擎索引提供数据，近来也为人工智能应用提供训练数据。<sup>[1](https://www.potaroo.net/ietf/ids/draft-illyes-aipref-cbcp-04.txt)</sup>

| 关键事实 | 详情 |
|---|---|
| 核心循环 | 取一个种子URL，解析其主机的IP地址，下载文档，提取其链接并去相对化，再将未见过的URL加回待抓取队列<sup>[2](https://www.cs.ucr.edu/~vagelis/classes/CS242/publications/scalable-crawler.pdf)</sup> |
| 访问控制 | 机器人排除协议由Martijn Koster于1994年提出，并于2022年9月标准化为RFC 9309，允许网站所有者通过robots.txt表达对爬虫访问的偏好<sup>[3](https://www.rfc-editor.org/rfc/rfc9309.html)</sup><sup> • </sup><sup>[4](https://blog.crawlex.net/blog/url-frontier-design/)</sup> |
| 礼貌性 | 许多行为良好的爬虫会限制对每个主机的并发连接数和请求速率，并可能在服务器返回HTTP 429或5xx时退避<sup>[5](https://nlp.stanford.edu/IR-book/html/htmledition/the-url-frontier-1.html)</sup><sup> • </sup><sup>[6](https://commoncrawl.org/faq)</sup> |
| 规模算术 | 一个月抓取十亿个页面需要每秒约400个页面，这迫使URL数据结构落到磁盘上<sup>[7](https://mirrors.meulie.net/bitsavers.org/pdf/dec/tech_reports/SRC-RR-173.pdf)</sup> |
| Common Crawl | 2008年至2025年共收集超过3000亿个页面，每月新增约25亿个，截至2025年9月数据量为10.1 PiB<sup>[8](https://raw.githubusercontent.com/commoncrawl/presentations/refs/heads/main/2025/Preserving_Humanity_s_Knowledge_and_Making_it_Accessible__Addressing_Challenges_of_Public_Web_Data.pdf)</sup> |
| 渲染成本 | 由于JavaScript执行开销，基于浏览器的抓取相对于静态HTML获取，吞吐量下降约一个数量级<sup>[9](https://www.usenix.org/system/files/nsdi24-goel.pdf)</sup> |
| AI时代的转变 | 2026年对500个网站的审计发现，训练类爬虫平均被41%的网站屏蔽，而检索类和用户触发类机器人仅被9%的网站屏蔽<sup>[10](https://crawlix.app/blog/ai-crawler-robots-data/)</sup> |

## 抓取的工作原理

基本算法取一组种子URL，反复取出一个URL，确定其主机名的[IP地址](https://www.edgepedia.org/zh/ip-address)，下载相应文档，并提取其中包含的链接。<sup>[2](https://www.cs.ucr.edu/~vagelis/classes/CS242/publications/scalable-crawler.pdf)</sup> 提取出的链接从相对形式转换为绝对形式，与已见过的URL集合进行比对，然后追加到待抓取页面的队列中。<sup>[2](https://www.cs.ucr.edu/~vagelis/classes/CS242/publications/scalable-crawler.pdf)</sup> 简单的先进先出队列产生对网络图的广度优先遍历，不过大多数超链接是相对链接，这使朴素实现变得复杂。<sup>[11](http://infolab.stanford.edu/%7Eolston/publications/crawling_survey.pdf)</sup>

**架构拆分。** 大型爬虫将决定下一步抓取什么的抓取应用，与处理大多数场景共有的任务（如机器人排除、抓取速度控制、DNS解析）的抓取系统分开。<sup>[12](https://research.engineering.nyu.edu/~suel/papers/crawl.pdf)</sup> 待抓取队列和已发现URL集合通常无法装入主内存，因此需要高效的基于磁盘的表示。<sup>[5](https://nlp.stanford.edu/IR-book/html/htmledition/the-url-frontier-1.html)</sup> [Common Crawl](https://www.edgepedia.org/zh/common-crawl)的Apache Nutch队列是一个极端案例：CrawlDb是一张磁盘表，记录每个已知URL及其抓取状态和评分，以生成、抓取、解析、更新这几个步骤的离散轮次处理，而非作为实时队列运行。<sup>[4](https://blog.crawlex.net/blog/url-frontier-design/)</sup>

大规模去重使用两个互补层：用于URL去重的布隆过滤器（Bloom filter），在1%假阳性率下，1000亿个URL约需120 GB；以及用于内容去重的SimHash，使用64位指纹，以[汉明距离](https://www.edgepedia.org/zh/hamming-distance)3为阈值进行比较。<sup>[13](https://hld.handbook.academy/curriculum/case-studies/web-crawler/)</sup>

## 礼貌性、robots.txt与同意信号

礼貌性是一组约束，使爬虫对任何服务器的容量占用不超过一个有限的份额。一个有礼貌的、带优先级的URL队列确保对任何主机同一时间只打开一个连接，对同一主机的连续请求之间等待几秒钟，并优先抓取高优先级页面。<sup>[5](https://nlp.stanford.edu/IR-book/html/htmledition/the-url-frontier-1.html)</sup> 一种常见策略是等待上次从服务器下载页面所耗时间的倍数（比如10倍），这限制了爬虫消耗该服务器资源的比例。<sup>[11](http://infolab.stanford.edu/%7Eolston/publications/crawling_survey.pdf)</sup> Mercator——1999年的参考设计——已经拒绝同时从同一Web服务器下载多个页面，并能对自身消耗的服务器资源比例施加限制。<sup>[7](https://mirrors.meulie.net/bitsavers.org/pdf/dec/tech_reports/SRC-RR-173.pdf)</sup>

**robots.txt。** 机器人排除协议始于1994年Martijn Koster在邮件列表中的提案，此后二十八年里靠惯例遵守，解释并不一致，直到2022年9月成为RFC 9309（一份拟议标准）。<sup>[4](https://blog.crawlex.net/blog/url-frontier-design/)</sup> 该RFC形式化了user-agent、allow和disallow等指令的语法和语义。<sup>[3](https://www.rfc-editor.org/rfc/rfc9309.html)</sup> 一份2024至2026年的IETF草案指出，行为良好的爬虫应支持该协议，以便参与的爬虫能尊重网站所有者不抓取的请求，并且即使不存在robots.txt文件，也应尊重X-Robots-Tag HTTP头。<sup>[1](https://www.potaroo.net/ietf/ids/draft-illyes-aipref-cbcp-04.txt)</sup> RFC 9309还允许在robots.txt中使用Sitemap指令；根据Sitemaps协议，每个站点地图文件上限为50,000个URL和50 MB未压缩大小，更大的网站使用站点地图索引，索引本身最多可列出50,000个子项。<sup>[14](https://sujeet.pro/articles/design-web-crawler)</sup>

**自适应退避。** 谷歌的爬虫在网站变慢或返回错误时自动降低抓取速率，以避免使其服务器过载；HTTP 500错误意味着“慢下来”。<sup>[15](https://developers.google.com/crawling/docs/about-crawling)</sup><sup> • </sup><sup>[16](https://developers.google.com/search/docs/fundamentals/how-search-works)</sup> Common Crawl的爬虫CCBot使用自适应退避算法，在服务器返回HTTP 429或5xx时减慢请求，并遵守robots.txt的Crawl-delay参数。<sup>[6](https://commoncrawl.org/faq)</sup>

## 扩展到整个网络

规模的算术驱动着架构。要在一个月内抓取十亿个页面，爬虫必须每秒下载约400个页面，其URL数据结构必须超出主内存扩展到磁盘上。<sup>[7](https://mirrors.meulie.net/bitsavers.org/pdf/dec/tech_reports/SRC-RR-173.pdf)</sup> Mercator在四台Compaq DS20E 666 MHz Alpha服务器上的抓取跑满了160 Mbit/秒的连接，在17天内每天下载约5000万份文档。<sup>[7](https://mirrors.meulie.net/bitsavers.org/pdf/dec/tech_reports/SRC-RR-173.pdf)</sup> BUbiNG是一个完全分布式的开源Java爬虫，在单台64核、64 GB内存的工作站上以每秒超过10,000个页面的速度下载数亿个页面，在主机和IP两个层面遵守礼貌性，数据存储速度超过160 MB/s；其速度随代理数量线性增长。<sup>[17](https://vigna.di.unimi.it/ftp/papers/BUbiNG.pdf)</sup>

**抓取策略。** 广度优先抓取平等地跟随所有链接，以广泛覆盖网络图，适合搜索引擎和存档；聚焦爬虫则先用分类器或关键词启发式对每个URL评分，再将其加入队列，优先访问高分URL；增量爬虫重新访问已索引的页面以捕捉变化，而非从头开始。<sup>[18](https://mbrenndoerfer.com/writing/web-crawling-common-crawl-strategies-robots-txt)</sup><sup> • </sup><sup>[19](https://www.browserless.io/blog/web-crawler)</sup> Common Crawl自2017年起使用Nutch的调和中心性进行种子选择，重访策略为30%新URL和70%重访。<sup>[8](https://raw.githubusercontent.com/commoncrawl/presentations/refs/heads/main/2025/Preserving_Humanity_s_Knowledge_and_Making_it_Accessible__Addressing_Challenges_of_Public_Web_Data.pdf)</sup>

## 数据一览

1999年5月运行的一次Mercator抓取在8天内发出了7740万次HTTP请求，使用一台配备两颗533 MHz Alpha处理器和2 GB内存的工作站，平均每秒112份文档、每秒1,682 KB。<sup>[2](https://www.cs.ucr.edu/~vagelis/classes/CS242/publications/scalable-crawler.pdf)</sup> Common Crawl是一家由Gil Elbaz于2007年创立的非营利组织，维护着自2008年以来收集的开放抓取数据仓库，总量超过10 PB，抓取数据大约每月发布一次，每次通常包含超过20亿个网页。<sup>[20](https://commoncrawl.org/about)</sup> 截至2025年9月，语料库跨越17年、超过3000亿个页面，已发布100多个抓取存档，数据量10.1 PiB。<sup>[8](https://raw.githubusercontent.com/commoncrawl/presentations/refs/heads/main/2025/Preserving_Humanity_s_Knowledge_and_Making_it_Accessible__Addressing_Challenges_of_Public_Web_Data.pdf)</sup> Common Crawl的CrawlDb包含约250亿个URL，按S3存储价格每月约40美元，其抓取合计每秒约抓取40,000个页面；这一速率主要受礼貌性规则和所用机器数量限制。<sup>[4](https://blog.crawlex.net/blog/url-frontier-design/)</sup>

一个针对大规模爬虫的系统设计估算示例：每天维持3330万个页面的抓取量，约每秒385个页面，按3倍峰值余量到每秒约1,200个页面，使用12至15个爬虫节点、每个每秒100个页面，网络受限约50 MB/s（约400 Mbps），假设平均响应500 KB。<sup>[14](https://sujeet.pro/articles/design-web-crawler)</sup> 现有证据尚不能确定可索引网络或深网的规模。<sup>[21](https://blog.lbenicio.dev/post/2025/05/28/implementing-a-scalable-web-crawler-with-distributed-frontier-and-politeness-policies/)</sup>

## JavaScript渲染及相关技术

传统爬虫下载页面的HTML，并递归抓取静态嵌入的图片、样式表和脚本链接。这已不再足够：现代页面上许多资源的URL在运行时才确定，因此动态爬虫在Chrome、Firefox或Edge等完整浏览器中执行JavaScript。<sup>[9](https://www.usenix.org/system/files/nsdi24-goel.pdf)</sup> 据估计超过60%的网络使用JavaScript渲染内容，通过无头浏览器抓取单个页面可能需要3到10秒，而静态HTML下载约需0.3秒。<sup>[21](https://blog.lbenicio.dev/post/2025/05/28/implementing-a-scalable-web-crawler-with-distributed-frontier-and-politeness-policies/)</sup> IETF草案指出，爬虫应主要使用HTTP GET请求，并仔细考虑或避免执行JavaScript造成的负载。<sup>[1](https://www.potaroo.net/ietf/ids/draft-illyes-aipref-cbcp-04.txt)</sup>

Googlebot在抓取期间使用较新版本的Chrome渲染页面并运行JavaScript。<sup>[16](https://developers.google.com/search/docs/fundamentals/how-search-works)</sup> 其流水线同步抓取HTML，稍后在Web渲染服务中渲染，索引器则协调两者。<sup>[14](https://sujeet.pro/articles/design-web-crawler)</sup> 大多数AI爬虫根本不渲染：GPTBot、ClaudeBot和PerplexityBot是普通HTTP客户端，解析初始HTML响应、文本、标题、元数据、JSON-LD、图片替代文本和链接，但几乎从不运行JavaScript，因此客户端水合的内容对它们不可见。<sup>[22](https://www.tengence.com/en/blog/article/how-llms-crawl-web/)</sup> Vercel测量了ChatGPT在纯[JavaScript](https://www.edgepedia.org/zh/javascript)渲染页面上的404率为34.82%，意味着爬虫只收到一个空壳。<sup>[22](https://www.tengence.com/en/blog/article/how-llms-crawl-web/)</sup> CCBot同样不执行JavaScript，也不使用cookie。<sup>[6](https://commoncrawl.org/faq)</sup>

渲染成本催生了混合设计。Sprinter在NSDI 2024上提出，结合了浏览器抓取与无浏览器抓取，抓取50,000个页面的语料库时，速度是基于浏览器抓取的5倍，同时在抓取的资源集合上与浏览器非常接近。<sup>[9](https://www.usenix.org/system/files/nsdi24-goel.pdf)</sup>

**爬虫与抓取器的区别。** 网络爬虫旨在广泛发现：从某个起点开始，通过跟随链接扩展；网络抓取器则旨在聚焦提取，访问某个特定页面或一组熟悉的页面，提取某个特定数据，如价格或评论评分。两者经常一起运行。<sup>[19](https://www.browserless.io/blog/web-crawler)</sup>

## 近期发展

AI时代的爬虫分为三类，网站对它们区别对待：训练类爬虫，如GPTBot、ClaudeBot、Google-Extended和CCBot，将内容纳入未来的训练集，今天不产生引用或流量；检索或搜索类爬虫，如OAI-SearchBot、Claude-SearchBot和PerplexityBot，构建实时索引并引用来源；用户触发类代理，如ChatGPT-User、Claude-User和Perplexity-User，在人类要求时按需抓取页面。<sup>[22](https://www.tengence.com/en/blog/article/how-llms-crawl-web/)</sup> Google-Extended只是一个robots.txt令牌，不是真正的爬虫：使用它控制内容是否有助于训练未来版本的Gemini模型，不影响网站在搜索中的收录。<sup>[15](https://developers.google.com/crawling/docs/about-crawling)</sup><sup> • </sup><sup>[22](https://www.tengence.com/en/blog/article/how-llms-crawl-web/)</sup>

网站已以差异化屏蔽作为回应。在2026年对500个网站的审计中，包括GPTBot、ClaudeBot、CCBot、Google-Extended、Bytespider、Amazonbot、Applebot-Extended、Meta-ExternalAgent、anthropic-ai和cohere-ai在内的训练类爬虫平均被41%的网站屏蔽，而OAI-SearchBot、PerplexityBot、ChatGPT-User和Claude-User等检索类和用户触发类机器人仅被9%的网站屏蔽。<sup>[10](https://crawlix.app/blog/ai-crawler-robots-data/)</sup> 在同一样本中，22%的网站屏蔽了至少一个训练机器人，同时明确允许至少一个检索机器人；35%的网站屏蔽训练机器人但未提及检索机器人；只有9%的网站屏蔽了所有与AI相关的爬虫。<sup>[10](https://crawlix.app/blog/ai-crawler-robots-data/)</sup> 自2025年7月起，[Cloudflare](https://www.edgepedia.org/zh/cloudflare)在其平台上的所有网站默认屏蔽AI爬虫，除非发布者选择加入或获得补偿。<sup>[13](https://hld.handbook.academy/curriculum/case-studies/web-crawler/)</sup> Cloudflare为380万个网站管理robots.txt，[WordPress](https://www.edgepedia.org/zh/wordpress)正以低速率限制屏蔽CCBot。<sup>[8](https://raw.githubusercontent.com/commoncrawl/presentations/refs/heads/main/2025/Preserving_Humanity_s_Knowledge_and_Making_it_Accessible__Addressing_Challenges_of_Public_Web_Data.pdf)</sup>

压力体现在抓取结果上。Common Crawl的抓取成功率从最初几次抓取时低于30%攀升到约80%，近年来又再次下降，因为更多网站通过robots.txt禁止抓取、以[HTTP 403](https://www.edgepedia.org/zh/http-403)拒绝，以及2022年引入的指数退避增加了被跳过URL的数量。<sup>[23](https://commoncrawl.github.io/cc-crawl-statistics/plots/crawlermetrics)</sup> Common Crawl已公布其迄今收到的所有法律请求所涉及的完整拒绝抓取名单，这些请求逐年增多。<sup>[8](https://raw.githubusercontent.com/commoncrawl/presentations/refs/heads/main/2025/Preserving_Humanity_s_Knowledge_and_Making_it_Accessible__Addressing_Challenges_of_Public_Web_Data.pdf)</sup>

## 检测、滥用与治理

根据IETF草案，可接受的抓取由若干实践定义：爬虫必须调节速度以免服务器不堪重负，避免过于频繁地重新抓取资源，限制抓取深度，并且除非网站所有者明确同意，不得绕过登录、验证码、付费墙或其他访问控制。<sup>[1](https://www.potaroo.net/ietf/ids/draft-illyes-aipref-cbcp-04.txt)</sup> 草案列出了绝大多数大型爬虫已应用的六项最佳实践：支持机器人排除协议、通过用户代理可识别、不干扰网站运行、支持缓存指令、以标准格式公开抓取IP范围、公开一个说明如何阻止抓取以及数据如何使用的页面。<sup>[1](https://www.potaroo.net/ietf/ids/draft-illyes-aipref-cbcp-04.txt)</sup> 谷歌声明其爬虫未经许可绝不进入付费墙或订阅内容。<sup>[15](https://developers.google.com/crawling/docs/about-crawling)</sup>

对不受欢迎爬虫的执法主要依赖两种机制：按用户代理模式屏蔽的WAF规则，以及针对机器人运营者公开IP范围的基于IP的屏蔽。<sup>[10](https://crawlix.app/blog/ai-crawler-robots-data/)</sup> 法律层面仍不确定。robots.txt提供了访问许可的社会契约，但并不授予版权许可，截至最近的相关技术写作，美国和欧洲以此为由挑战大型AI公司的诉讼仍在进行，尚无定论。<sup>[18](https://mbrenndoerfer.com/writing/web-crawling-common-crawl-strategies-robots-txt)</sup>

## References

1. [IETF Internet-Draft: AI Preferences Content Blocking and Control (draft-illyes-aipref-cbcp-04)](https://www.potaroo.net/ietf/ids/draft-illyes-aipref-cbcp-04.txt)
2. [Heydon & Najork, Mercator: A Scalable, Extensible Web Crawler](https://www.cs.ucr.edu/~vagelis/classes/CS242/publications/scalable-crawler.pdf)
3. [RFC 9309: Robots Exclusion Protocol](https://www.rfc-editor.org/rfc/rfc9309.html)
4. [URL frontier design: from Mercator to modern priority-queue crawlers](https://blog.crawlex.net/blog/url-frontier-design/)
5. [The URL frontier, Introduction to Information Retrieval (Stanford)](https://nlp.stanford.edu/IR-book/html/htmledition/the-url-frontier-1.html)
6. [Common Crawl FAQ](https://commoncrawl.org/faq)
7. [High-Performance Web Crawling, Compaq SRC Research Report 173](https://mirrors.meulie.net/bitsavers.org/pdf/dec/tech_reports/SRC-RR-173.pdf)
8. [Preserving Humanity's Knowledge and Making it Accessible (Common Crawl, 2025)](https://raw.githubusercontent.com/commoncrawl/presentations/refs/heads/main/2025/Preserving_Humanity_s_Knowledge_and_Making_it_Accessible__Addressing_Challenges_of_Public_Web_Data.pdf)
9. [Sprinter: Speeding Up High-Fidelity Crawling of the Modern Web, NSDI 2024](https://www.usenix.org/system/files/nsdi24-goel.pdf)
10. [We Audited 500 Sites for AI Crawler Access in 2026](https://crawlix.app/blog/ai-crawler-robots-data/)
11. [Olston & Najork, Web Crawling survey](http://infolab.stanford.edu/%7Eolston/publications/crawling_survey.pdf)
12. [Design and Implementation of a High-Performance Distributed Web Crawler](https://research.engineering.nyu.edu/~suel/papers/crawl.pdf)
13. [Design a Web Crawler (Googlebot-style), The HLD Handbook](https://hld.handbook.academy/curriculum/case-studies/web-crawler/)
14. [Design a Web Crawler, Sujeet Jaiswal](https://sujeet.pro/articles/design-web-crawler)
15. [Things to Know about Google's Web Crawling](https://developers.google.com/crawling/docs/about-crawling)
16. [In-Depth Guide to How Google Search Works](https://developers.google.com/search/docs/fundamentals/how-search-works)
17. [BUbiNG: Massive Crawling for the Masses](https://vigna.di.unimi.it/ftp/papers/BUbiNG.pdf)
18. [Web Crawling: Common Crawl, Robots.txt, and Freshness](https://mbrenndoerfer.com/writing/web-crawling-common-crawl-strategies-robots-txt)
19. [Web Crawlers: How They Work, and Where They Break](https://www.browserless.io/blog/web-crawler)
20. [Common Crawl About](https://commoncrawl.org/about)
21. [Implementing a Scalable Web Crawler With Distributed Frontier And Politeness Policies](https://blog.lbenicio.dev/post/2025/05/28/implementing-a-scalable-web-crawler-with-distributed-frontier-and-politeness-policies/)
22. [How LLMs Fetch Web Pages: The Full Chain of Crawling, Fetching, and Parsing](https://www.tengence.com/en/blog/article/how-llms-crawl-web/)
23. [Statistics of Common Crawl Monthly Archives, Crawler Metrics](https://commoncrawl.github.io/cc-crawl-statistics/plots/crawlermetrics)

---
*Initially written Sep 17, 2026 · Reviewed: Sep 30, 2026; Oct 15, 2026 · Edited: Sep 30, 2026; Oct 15, 2026 · Last review: Oct 15, 2026*

Topic: 技术与人造世界 › 计算技术与数字系统 › 网络与安全 › HTTP and web communication protocols

Copyright 2026 Edgepedia

License: Edgepedia Community License 1.0, https://www.edgepedia.org/edgepedia/license

Source: https://www.edgepedia.org/zh/web-crawler

English original: https://www.edgepedia.org/web-crawler
